What is the Quickest Way to Check If All Values in an Array Are Numeric?
assuming your array is one-dimensional and just made up of integers:
return ctype_digit(implode('',$array));
Filter the array using is_numeric. If the size of the result is the same as the original, then all items are numeric:
$array = array( 1, '2', '45' );
if ( count( $array ) === count( array_filter( $array, 'is_numeric' ) ) ) {
// all numeric
}
array_map("is_numeric", array(1,2,"3","hello"))
Array ( [0] => 1 [1] => 1 [2] => 1 [3] => )