File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff 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
466505Groups an associative array by keys.
You can’t perform that action at this time.
0 commit comments