note 51643 deleted from ref.array by nlopess
| From: | nlopess@php.net | Date: | Wed, 06 Apr 2005 13:49:00 +0000 |
| Subject: | note 51643 deleted from ref.array by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-87578@lists.php.net to get a copy of this message | ||
Note Submitter: xavier (at) ladragonera (dot) com
Reason: useless
----
How to count dimensions in multi-array.
The last post which corrects an other fails in arrays that include an element that is not an array,
an array, and other no array element because is setting always 1 when is not an array. Also,
don't look every element inside an array.
I put it inside a foreach and ask (when is not an array) if the previous return value is greater.
Here is the code:
function ContarDimensions($ArrayDonat)
{
foreach ($ArrayDonat as $Registre)
{
if (is_array($Registre))
{
$return = ContarDimensions($Registre) + 1;
}
else
{
if ($return<=1)
{
$return = 1;
}
}
}
return $return;
}
Sorry my poor english.
I'm new in PHP, so maybe it can be done better.