wpseek.com
Bazujące na WordPress narzędzie wyszukiwania dla deweloperów i twórców motywów.



array_find › WordPress Function

Od6.8.0
Przestarzałyn/a
› array_find ( $array, $callback )
Parametry: (2)
  • (array) $array The array to search.
    Wymagane: Tak
  • (callable) $callback The callback to run for each element.
    Wymagane: Tak
Powrót:
  • (mixed|null) The first element in the array that passes the `$callback`, otherwise null.
Zdefiniowane na:
Codex:

Polyfill for `array_find()` function added in PHP 8.4.

Searches an array for the first element that passes a given callback.


Źródło

function array_find( array $array, callable $callback ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound
		foreach ( $array as $key => $value ) {
			if ( $callback( $value, $key ) ) {
				return $value;
			}
		}

		return null;
	}
}