note 79924 added to function.is-array

From: Date: Wed, 19 Dec 2007 21:14:24 +0000
Subject: note 79924 added to function.is-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-133793@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 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! ?> ---- Server IP: 82.177.164.100 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/79924 Del: integrated -- https://master.php.net/note/delete/79924/integrated Del: useless -- https://master.php.net/note/delete/79924/useless Del: bad code -- https://master.php.net/note/delete/79924/bad+code Del: spam -- https://master.php.net/note/delete/79924/spam Del: non-english -- https://master.php.net/note/delete/79924/non-english Del: in docs -- https://master.php.net/note/delete/79924/in+docs Del: other reasons-- https://master.php.net/note/delete/79924 Reject -- https://master.php.net/note/reject/79924 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#133793) next »