| @@ 123-131 (lines=9) @@ | ||
| 120 | * @param callable $callback | |
| 121 | * @return mix | |
| 122 | */ | |
| 123 | public function find(callable $callback) | |
| 124 |     { | |
| 125 | $array = $this->getArrayCopy(); | |
| 126 |         foreach ($array as $key => $value) { | |
| 127 |             if ($callback($value, $key, $array) === true) { | |
| 128 | return $value; | |
| 129 | } | |
| 130 | } | |
| 131 | } | |
| 132 | ||
| 133 | /** | |
| 134 | * The findIndex() method returns an index of the first element in the array that satisfies the provided testing function. | |
| @@ 140-150 (lines=11) @@ | ||
| 137 | * @param callable $callback | |
| 138 | * @return int|string | |
| 139 | */ | |
| 140 | public function findIndex(callable $callback) | |
| 141 |     { | |
| 142 | $array = $this->getArrayCopy(); | |
| 143 |         foreach ($array as $key => $value) { | |
| 144 |             if ($callback($value, $key, $array) === true) { | |
| 145 | return $key; | |
| 146 | } | |
| 147 | } | |
| 148 | ||
| 149 | return -1; | |
| 150 | } | |
| 151 | ||
| 152 | /** | |
| 153 | * The forEach() method executes a provided function once for each array element. | |