+2  A: 

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
Couldn't seem to get this to work at all on the sample array, i var_exported the sample array now (edit on the question).
youdontmeanmuch
My function was using the 'depth' keys in the original array but now they're gone. I edited the function to find the depth on its own and it seems to work on your sample array now.
yjerem
Awesome, it makes sense... and it works :D thank you very much!
youdontmeanmuch
A: 

I really want to say this will work

function deep(&$layer)
{
    $count = 1;
    $keys = array_keys($layer);
    foreach($keys as $key)
     if(is_array($layer[$key]))
      deep($layer[$key]);
    $layer['depth'] = $count++;
}

(Tested and works fine for me) (Another case of me misunderstanding the question. This should be what you want)

Zachery Delafosse
Yea i think you mis understood the question (sorry i didn't make this clear) I already have a function to set the depth, i need something to set the [count] on the sample array.
youdontmeanmuch