【发布时间】:2015-08-07 20:54:13
【问题描述】:
我正在尝试从数组中检索键“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"));
?>
【问题讨论】:
标签: php