note 79924 deleted from function.is-array by tularis

From: Date: Sun, 09 Oct 2011 09:28:59 +0000
Subject: note 79924 deleted from function.is-array by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-183744@lists.php.net to get a copy of this message
Note Submitter: DJ ProG (Poland, Lodz) ---- Hi. My boolean function returns true, if all values in array are that same type (like in my funct. - it checks, if all are numeric). <?php function isNumArray($array) { $r = false; if (is_array($array)) { foreach($array as $n=>$v) { if (is_array( $array[$n] )) { $r = isNumArray( $array[$n] ); if ($r==false) break; } else if (!is_numeric($v)) { $r=false; break; } else $r=true; } } return $r; } # example $arr1 = array('34', 3.14, array('321', 092), '2', 55, -173, array('1.98', '-044'), '0'); $arr2 = array('3 4', 3.14, array('-321', 56, 0-92), '2', 55, true, array('zero44'), '0'); echo '1. '.(isNumArray($arr1) ? 'Only numz.' : 'Various values!')."\r\n". '2. '.(isNumArray($arr2) ? 'Only numz.' : 'Various values!'); # return # 1. Only numz. # 2. Various values! ?>

« previous php.notes (#183744) next »