array_all() returnstrue, if the givencallback returnstrue for all elements. Otherwise the function returnsfalse.
The function returnstrue, ifcallback returnstrue for all elements. Otherwise the function returnsfalse.
Example #1array_all() example
<?php
$array= [
'a'=>'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) {
returnstrlen($value) <12;
}));
// Check, if all animal names are longer than 5 letters.
var_dump(array_all($array, function (string $value) {
returnstrlen($value) >5;
}));
// Check, if all array keys are strings.
var_dump(array_all($array, function (string $value,$key) {
returnis_string($key);
}));
?>The above example will output:
bool(true)bool(false)bool(true)
