note 79833 added to function.is-array

From: Date: Fri, 14 Dec 2007 18:53:29 +0000
Subject: note 79833 added to function.is-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-133458@lists.php.net to get a copy of this message
Hi. My boolean function returns true, if all values in array are that same type (like this - it's checking, 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! ?> ---- Server IP: 82.160.94.10 Probable Submitter: 195.69.81.203 ---- Manual Page -- http://www.php.net/manual/en/function.is-array.php Edit -- https://master.php.net/note/edit/79833 Del: integrated -- https://master.php.net/note/delete/79833/integrated Del: useless -- https://master.php.net/note/delete/79833/useless Del: bad code -- https://master.php.net/note/delete/79833/bad+code Del: spam -- https://master.php.net/note/delete/79833/spam Del: non-english -- https://master.php.net/note/delete/79833/non-english Del: in docs -- https://master.php.net/note/delete/79833/in+docs Del: other reasons-- https://master.php.net/note/delete/79833 Reject -- https://master.php.net/note/reject/79833 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#133458) next »