note 110293 added to function.is-array

From: Date: Mon, 08 Oct 2012 22:16:18 +0000
Subject: note 110293 added to function.is-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-191191@lists.php.net to get a copy of this message
<?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)*/?> ---- Server IP: 194.8.30.16 Probable Submitter: 85.247.247.213 ---- Manual Page -- http://www.php.net/manual/en/function.is-array.php Edit -- https://master.php.net/note/edit/110293 Del: integrated -- https://master.php.net/note/delete/110293/integrated Del: useless -- https://master.php.net/note/delete/110293/useless Del: bad code -- https://master.php.net/note/delete/110293/bad+code Del: spam -- https://master.php.net/note/delete/110293/spam Del: non-english -- https://master.php.net/note/delete/110293/non-english Del: in docs -- https://master.php.net/note/delete/110293/in+docs Del: other reasons-- https://master.php.net/note/delete/110293 Reject -- https://master.php.net/note/reject/110293 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#191191) next »