Array ( [0] => Array ( [id] => 15 [pid] => 0 [module_id] => comments1 ( [0] => Array ( [id] => 16 [pid] => 15 [module_id] => comments1 ( [0] => Array ( [id] => 21 [pid] => 16 [module_id] => comments1 ) ) ) ) )
function array_level (array $arr, $search_element, $key='id' , $parent = 'module_id') { $i= isset($i) ? $i : 1; foreach ($arr as $val) { if ($val[$key] == $element) return $i; else { $i++; array_level($val[$parent], $search_elementю, $key); } } return false; } $level = array_level($array, '21');