diff --git a/reference/array/functions/array-all.xml b/reference/array/functions/array-all.xml new file mode 100644 index 000000000000..4038689cfb9e --- /dev/null +++ b/reference/array/functions/array-all.xml @@ -0,0 +1,134 @@ + + + + + array_all + Checks if all &array; elements satisfy a callback function + + + + &reftitle.description; + + mixedarray_all + arrayarray + callablecallback + + + array_all returns &true;, if the given + callback returns &true; for all elements. + Otherwise the function returns &false;. + + + + + &reftitle.parameters; + + + array + + + The &array; that should be searched. + + + + + callback + + + The callback function to call to check each element, which must be + + boolcallback + mixedvalue + mixedkey + + If this function returns &false;, &false; is returned from + array_all and the callback will not be called for + further elements. + + + + + + + + &reftitle.returnvalues; + + The function returns &true;, if callback returns + &true; for all elements. Otherwise the function returns &false;. + + + + + &reftitle.examples; + + <function>array_all</function> example + + 'dog', + 'b' => 'cat', + 'c' => 'cow', + 'd' => 'duck', + 'e' => 'goose', + 'f' => 'elephant' +]; + +// Check, if all animal names are shorter than 12 letters. +var_dump(array_all($array, function (string $value) { + return strlen($value) < 12; +})); + +// Check, if all animal names are longer than 5 letters. +var_dump(array_all($array, function (string $value) { + return strlen($value) > 5; +})); + +// Check, if all array keys are strings. +var_dump(array_all($array, function (string $value, $key) { + return is_string($key); +})); +?> +]]> + + &example.outputs; + + + + + + + + &reftitle.seealso; + + array_any + array_filter + array_find + array_find_key + + + + diff --git a/reference/array/functions/array-any.xml b/reference/array/functions/array-any.xml new file mode 100644 index 000000000000..75c779bc414b --- /dev/null +++ b/reference/array/functions/array-any.xml @@ -0,0 +1,135 @@ + + + + + array_any + Checks if at least one &array; element satisfies a callback function + + + + &reftitle.description; + + mixedarray_any + arrayarray + callablecallback + + + array_any returns &true;, if the given + callback returns &true; for any element. + Otherwise the function returns &false;. + + + + + &reftitle.parameters; + + + array + + + The &array; that should be searched. + + + + + callback + + + The callback function to call to check each element, which must be + + boolcallback + mixedvalue + mixedkey + + If this function returns &true;, &true; is returned from + array_any and the callback will not be called for + further elements. + + + + + + + + &reftitle.returnvalues; + + The function returns &true;, if there is at least one element for which + callback returns &true;. Otherwise the function + returns &false;. + + + + + &reftitle.examples; + + <function>array_any</function> example + + 'dog', + 'b' => 'cat', + 'c' => 'cow', + 'd' => 'duck', + 'e' => 'goose', + 'f' => 'elephant' +]; + +// Check, if any animal name is longer than 5 letters. +var_dump(array_any($array, function (string $value) { + return strlen($value) > 5; +})); + +// Check, if any animal name is shorter than 3 letters. +var_dump(array_any($array, function (string $value) { + return strlen($value) < 3; +})); + +// Check, if any array key is not a string. +var_dump(array_any($array, function (string $value, $key) { + return !is_string($key); +})); +?> +]]> + + &example.outputs; + + + + + + + + &reftitle.seealso; + + array_all + array_filter + array_find + array_find_key + + + + diff --git a/reference/array/functions/array-filter.xml b/reference/array/functions/array-filter.xml index 0c1190c8ce13..fabe1b3e1ee3 100644 --- a/reference/array/functions/array-filter.xml +++ b/reference/array/functions/array-filter.xml @@ -5,7 +5,7 @@ array_filter Filters elements of an array using a callback function - + &reftitle.description; @@ -201,7 +201,7 @@ Array - <function>array_filter</function> with + <title><function>array_filter</function> with <parameter>mode</parameter> array_intersect + array_find + array_any array_map array_reduce - array_walk diff --git a/reference/array/functions/array-find-key.xml b/reference/array/functions/array-find-key.xml new file mode 100644 index 000000000000..de6e965b5a6b --- /dev/null +++ b/reference/array/functions/array-find-key.xml @@ -0,0 +1,142 @@ + + + + + array_find_key + Returns the key of the first element satisfying a callback function + + + + &reftitle.description; + + mixedarray_find_key + arrayarray + callablecallback + + + array_find_key returns the key of the first element of an + &array; for which the given callback returns &true;. + If no matching element is found the function returns &null;. + + + + + &reftitle.parameters; + + + array + + + The &array; that should be searched. + + + + + callback + + + The callback function to call to check each element, which must be + + boolcallback + mixedvalue + mixedkey + + If this function returns &true;, the key is returned from + array_find_key and the callback will not be called + for further elements. + + + + + + + + &reftitle.returnvalues; + + The function returns the key of the first element for which the + callback returns &true;. If no matching element is + found the function returns &null;. + + + + + &reftitle.examples; + + <function>array_find_key</function> example + + 'dog', + 'b' => 'cat', + 'c' => 'cow', + 'd' => 'duck', + 'e' => 'goose', + 'f' => 'elephant' +]; + +// Find the first animal with a name longer than 4 characters. +var_dump(array_find_key($array, function (string $value) { + return strlen($value) > 4; +})); + +// Find the first animal whose name begins with f. +var_dump(array_find_key($array, function (string $value) { + return str_starts_with($value, 'f'); +})); + +// Find the first animal where the array key is the first symbol of the animal. +var_dump(array_find_key($array, function (string $value, $key) { + return $value[0] === $key; +})); + +// Find the first animal where the array key matching a RegEx. +var_dump(array_find_key($array, function ($value, $key) { + return preg_match('/^([a-f])$/', $key); +})); +?> +]]> + + &example.outputs; + + + + + + + + &reftitle.seealso; + + array_find + array_all + array_any + array_filter + array_reduce + + + + diff --git a/reference/array/functions/array-find.xml b/reference/array/functions/array-find.xml new file mode 100644 index 000000000000..1334e7530d43 --- /dev/null +++ b/reference/array/functions/array-find.xml @@ -0,0 +1,142 @@ + + + + + array_find + Returns the first element satisfying a callback function + + + + &reftitle.description; + + mixedarray_find + arrayarray + callablecallback + + + array_find returns the value of the first element of an + &array; for which the given callback returns &true;. + If no matching element is found the function returns &null;. + + + + + &reftitle.parameters; + + + array + + + The &array; that should be searched. + + + + + callback + + + The callback function to call to check each element, which must be + + boolcallback + mixedvalue + mixedkey + + If this function returns &true;, the value is returned from + array_find and the callback will not be called for + further elements. + + + + + + + + &reftitle.returnvalues; + + The function returns the value of the first element for which the + callback returns &true;. If no matching element is + found the function returns &null;. + + + + + &reftitle.examples; + + <function>array_find</function> example + + 'dog', + 'b' => 'cat', + 'c' => 'cow', + 'd' => 'duck', + 'e' => 'goose', + 'f' => 'elephant' +]; + +// Find the first animal with a name longer than 4 characters. +var_dump(array_find($array, function (string $value) { + return strlen($value) > 4; +})); + +// Find the first animal whose name begins with f. +var_dump(array_find($array, function (string $value) { + return str_starts_with($value, 'f'); +})); + +// Find the first animal where the array key is the first symbol of the animal. +var_dump(array_find($array, function (string $value, $key) { + return $value[0] === $key; +})); + +// Find the first animal where the array key matching a RegEx. +var_dump(array_find($array, function ($value, $key) { + return preg_match('/^([a-f])$/', $key); +})); +?> +]]> + + &example.outputs; + + + + + + + + &reftitle.seealso; + + array_find_key + array_all + array_any + array_filter + array_reduce + + + + diff --git a/reference/array/versions.xml b/reference/array/versions.xml index ca37edd339cc..82064ec2e97e 100644 --- a/reference/array/versions.xml +++ b/reference/array/versions.xml @@ -5,6 +5,8 @@ --> + + @@ -18,6 +20,8 @@ + +