If you wants to make a checkup ones array is multi dimension or not ?
Here is the way
$array
Count array twice,once normal count and second time with COUNT_RECURSIVE parameter.and check whether those are equal or not?
If they equal that array is Single Dimension.
If not that array is Multi Dimension.
<?php
?>if (count($myarray) == count($myarray, COUNT_RECURSIVE)) { echo 'MyArray is not multidimensional'; } else { echo 'MyArray is multidimensional'; }
Differences with Count and Recursive Count
<?php
$food = array('fruits' => array('orange', 'banana', 'apple'),
'veggie' => array('carrot', 'collard', 'pea'));// recursive count
echo count($food, COUNT_RECURSIVE);
// output 8
// normal count echo count($food); // output 2?>

No comments:
Post a Comment