@@ 133-141 (lines=9) @@ | ||
130 | * @param callable $callback |
|
131 | * @return mix |
|
132 | */ |
|
133 | public function find(callable $callback) |
|
134 | { |
|
135 | $array = $this->getArrayCopy(); |
|
136 | foreach ($array as $key => $value) { |
|
137 | if ($callback($value, $key, $array) === true) { |
|
138 | return $value; |
|
139 | } |
|
140 | } |
|
141 | } |
|
142 | ||
143 | /** |
|
144 | * The findIndex() method returns an index of the first element in the array that satisfies the provided testing function. |
|
@@ 150-160 (lines=11) @@ | ||
147 | * @param callable $callback |
|
148 | * @return int|string |
|
149 | */ |
|
150 | public function findIndex(callable $callback) |
|
151 | { |
|
152 | $array = $this->getArrayCopy(); |
|
153 | foreach ($array as $key => $value) { |
|
154 | if ($callback($value, $key, $array) === true) { |
|
155 | return $key; |
|
156 | } |
|
157 | } |
|
158 | ||
159 | return -1; |
|
160 | } |
|
161 | ||
162 | /** |
|
163 | * The forEach() method executes a provided function once for each array element. |