CLI_Command::array_find
Returns the the first element of the passed array for which the callback returns true.
Polyfill for the array_find() introduced in PHP 8.3.
Метод класса: CLI_Command{}
Хуков нет.
Возвращает
Разное. First array element for which the callback returns true, null otherwise.
Использование
// private - только в коде основоного (родительского) класса $result = $this->array_find( $arr, $callback );
- $arr(массив) (обязательный)
- Array to search.
- $callback(callable) (обязательный)
- The callback function for each element in the array.
Код CLI_Command::array_find() CLI Command::array find WP-CLI 2.13.0-alpha
private function array_find( $arr, $callback ) {
if ( function_exists( '\array_find' ) ) {
// phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.array_findFound
return \array_find( $arr, $callback );
}
foreach ( $arr as $key => $value ) {
if ( $callback( $value, $key ) ) {
return $value;
}
}
return null;
}