| @@ 1064-1091 (lines=28) @@ | ||
| 1061 | * |
|
| 1062 | * @return static |
|
| 1063 | */ |
|
| 1064 | public function arsort(int $option = SORT_REGULAR): Collection |
|
| 1065 | { |
|
| 1066 | $index = 0; |
|
| 1067 | $items = $this->items; |
|
| 1068 | ||
| 1069 | foreach ($items as &$item) { |
|
| 1070 | $item = [$index++, $item]; |
|
| 1071 | } |
|
| 1072 | ||
| 1073 | uasort($items, function ($a, $b) use ($option) { |
|
| 1074 | if ($a[1] === $b[1]) { |
|
| 1075 | return $a[0] - $b[0]; |
|
| 1076 | } |
|
| 1077 | ||
| 1078 | $set = [-1 => $b[1], 1 => $a[1]]; |
|
| 1079 | ||
| 1080 | asort($set, $option); |
|
| 1081 | reset($set); |
|
| 1082 | ||
| 1083 | return key($set); |
|
| 1084 | }); |
|
| 1085 | ||
| 1086 | foreach ($items as &$item) { |
|
| 1087 | $item = $item[1]; |
|
| 1088 | } |
|
| 1089 | ||
| 1090 | return new static($items); |
|
| 1091 | } |
|
| 1092 | ||
| 1093 | /** |
|
| 1094 | * Sort an array and maintain index association. |
|
| @@ 1100-1127 (lines=28) @@ | ||
| 1097 | * |
|
| 1098 | * @return static |
|
| 1099 | */ |
|
| 1100 | public function asort(int $option = SORT_REGULAR): Collection |
|
| 1101 | { |
|
| 1102 | $index = 0; |
|
| 1103 | $items = $this->items; |
|
| 1104 | ||
| 1105 | foreach ($items as &$item) { |
|
| 1106 | $item = [$index++, $item]; |
|
| 1107 | } |
|
| 1108 | ||
| 1109 | uasort($items, function ($a, $b) use ($option) { |
|
| 1110 | if ($a[1] === $b[1]) { |
|
| 1111 | return $a[0] - $b[0]; |
|
| 1112 | } |
|
| 1113 | ||
| 1114 | $set = [-1 => $a[1], 1 => $b[1]]; |
|
| 1115 | ||
| 1116 | asort($set, $option); |
|
| 1117 | reset($set); |
|
| 1118 | ||
| 1119 | return key($set); |
|
| 1120 | }); |
|
| 1121 | ||
| 1122 | foreach ($items as &$item) { |
|
| 1123 | $item = $item[1]; |
|
| 1124 | } |
|
| 1125 | ||
| 1126 | return new static($items); |
|
| 1127 | } |
|
| 1128 | ||
| 1129 | /** |
|
| 1130 | * Sort an array using a case insensitive "natural order" algorithm. |
|