I think this should work... I wasn't able to test on your example array but it seems to work on a smaller array I made.
Edit: Changed the function now that you've removed the 'depth' keys from your example array. Now it finds the depth on its own. I've also added my test code and output:
<?php
function array_depth_count(&$array, $count=array(), $depth=1) {
foreach ($array as &$value) {
if (is_array($value)) {
$value['count'] = ++$count[$depth];
array_depth_count($value, $count, $depth + 1);
}
}
}
$a = array(array(array(array(0),array(0),array(),array()),0,array()));
echo "Before\n";
print_r($a);
array_depth_count($a);
echo "\n\nAfter\n";
print_r($a);
?>
Output:
Before
Array
(
[0] => Array
(
[0] => Array
(
[0] => Array
(
[0] => 0
)
[1] => Array
(
[0] => 0
)
[2] => Array
(
)
[3] => Array
(
)
)
[1] => 0
[2] => Array
(
)
)
)
After
Array
(
[0] => Array
(
[0] => Array
(
[0] => Array
(
[0] => 0
[count] => 1
)
[1] => Array
(
[0] => 0
[count] => 2
)
[2] => Array
(
[count] => 3
)
[3] => Array
(
[count] => 4
)
[count] => 1
)
[1] => 0
[2] => Array
(
[count] => 2
)
[count] => 1
)
)
yjerem
2009-02-07 08:23:51