<?php

$cat = array(
  "Name"    => "Percy",
  "Colour"  => "Black",
  "Hobbies" => array(
    1 => "Chasing mice",
    2 => "Sleeping",
    3 => "Prowling"
  ),
   "Name"    => "Jackson",
);


$cat2 = array(
	'count' => 1,
	0 => array(
		'cn' => array(
			'count' => 1,
			0 => 'abcd',
		) ,
		0 => 'cn',
		'count' => 1,
		'dn' => 'cn=abcd,ou=test,dc=myproj,dc=com',
	) ,
);

$output = "";
// Find the value of a Key
function seekKey($haystack, $needle){
	global $output;
  foreach($haystack as $key => $value){
    if($key == $needle){
      $output = $value;
    
    }elseif(is_array($value)){
      $output = seekKey($value, $needle);
     
    }
  }
  return $output;
}

var_export(seekKey($cat2,"dn"));

?>