我想从数组中检索一个键“dn
”的值。PHP需要检索密钥:从阵列的'dn'值
这里是我的代码:https://ideone.com/3gUfWs
输出越来越为:
array (
'cn' =>
array (
'count' => 1,
0 => 'abcd',
),
0 => 'cn',
'count' => 1,
'dn' => 'cn=abcd,ou=test,dc=myproj,dc=com',
)
但我需要的是输出:cn=abcd,ou=test,dc=myproj,dc=com
顺便说一句,这里提供了我相同的代码在上面的链接中:
<?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"));
?>