note 110293 deleted from function.is-array by googleguy

From: Date: Tue, 09 Oct 2012 01:31:33 +0000
Subject: note 110293 deleted from function.is-array by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-191196@lists.php.net to get a copy of this message
Note Submitter: espertalhao04 at hotmail dot com ---- <?php /*Verifies if the array is 2D (has another array inside) or not *@param *@$a array to check *@$t defines if returns an array or not *@$c counts the number of values inside the resulting array (only with $c set to true) * *@returns *NULL if $a is not an array *bool if $t is false *array with a list of bools if $t is true *array with a list of arrays with bool and the count of elements if it is an array if $c is true *keys: '2D','2d',0 => bool, 'count',1=>count of elements */ function is2D($a,$t=false,$c=false) { if(!is_array($a)){return NULL;} $k=array_keys($a); $i=0; while($n = @$a[@$k[@$i++]]) { if($t===true) if($c===true) @$o[$i-1]=array(($y=is_array($n)),($z=count($n)),"2D"=>$y,"2d"=>$y,"count"=>$z); else @$o[$i-1]=is_array($n); else @$o=((@$o)?@$o:is_array($n)); } return @$o; } echo var_dump(is2D(array("a",array("b")),true,true)); /*returns: array(2) { [0]=> array(5) { [0]=>bool(false) [1]=>int(1) ["2D"]=>bool(false) ["2d"]=>bool(false) ["count"]=>int(1) } [1]=> array(5) { [0]=>bool(true) [1]=>int(1) ["2D"]=>bool(true) ["2d"]=>bool(true) ["count"]=>int(1) } }*/ echo var_dump(is2D(array("a",array("b"),"a"))); /*returns: bool(true)*/?>

« previous php.notes (#191196) next »