Skip to content

Commit fcfaaac

Browse files
authored
Update README.md
1 parent 777cfba commit fcfaaac

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,45 @@ array (
461461
)
462462
```
463463

464+
Keep index
465+
466+
```php
467+
$associativeArray = new AssociativeArray([
468+
'X' => ['id' => 1001, 'category' => 'C', 'price' => 10],
469+
'Y' => ['id' => 1002, 'category' => 'A', 'price' => 25],
470+
'Z' => ['id' => 1003, 'category' => 'B', 'price' => 10],
471+
]);
472+
473+
$result = $associativeArray->orderBy('category', 'asc', true)->toArray();
474+
475+
var_export($result);
476+
```
477+
478+
Result:
479+
480+
```php
481+
array (
482+
'Y' =>
483+
array (
484+
'id' => 1002,
485+
'category' => 'A',
486+
'price' => 25,
487+
),
488+
'Z' =>
489+
array (
490+
'id' => 1003,
491+
'category' => 'B',
492+
'price' => 10,
493+
),
494+
'X' =>
495+
array (
496+
'id' => 1001,
497+
'category' => 'C',
498+
'price' => 10,
499+
),
500+
)
501+
```
502+
464503
### groupBy()
465504

466505
Groups an associative array by keys.

0 commit comments

Comments
 (0)