la*****@gmail.com wrote:
I would like to use the is_numeric() function to check each element of
an array. I am just looking for a false if any element is not numeric,
or a true if each element is numeric.
Can I do this with a single function in a single like, or do I have to
do a foreach{ ... break() } structure?
You can do so. But it may be more difficult to understand:
$result = (count(array_filter($arr, "is_numeric" ))=count($arr))
or try this:
$result = !in_array(false, array_map("is_numeric", $arr))
or try this:
Once declare r_is_numeric like this:
function r_is_numeric($logic, $element)
{
$logic = $logic and is_numeric($element);
return $logic;
}
All you need is:
$result = array_reduce($arr, "r_is_numeric", true);
Heiko