I am trying to retrieve value of a key (dn
) from an array.
Here is my code: https://ideone.com/3gUfWs
Output getting as:
array (
'cn' =>
array (
'count' => 1,
0 => 'abcd',
),
0 => 'cn',
'count' => 1,
'dn' => 'cn=abcd,ou=test,dc=myproj,dc=com',
)
But What I need output as:
cn=abcd,ou=test,dc=myproj,dc=com
BTW, here is my same code provided in above link:
$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"));