我有一个数组,我正在尝试解决如何循环它将键指定为php变量,值为php值。
Array
(
[count] => 1
[0] => Array
(
[cn] => Array
(
[count] => 1
[0] => Distributed Site
)
[0] => cn
[description] => Array
(
[count] => 1
[0] => Multisite Location
)
[1] => description
[location] => Array
(
[count] => 1
[0] => b0e81b22-4448-48d2-b641-515b6d4f38d7
)
[2] => location
[owner] => Array
(
[count] => 1
[0] => ec19c2db-25ec-4e89-8143-8864417e4f23
)
[3] => owner
[count] => 4
[dn] => cn=Distributed Site,cn=Local,cn=Sites
)
)
所以我最终会以
结束$cn with a value of 'Distrusted Site'
$description with a value of 'Multisite Location'
$location with a value of 'b0e81b22-4448-48d2-b641-515b6d4f38d7'
等。
知道怎么做吗?
由于
答案 0 :(得分:0)
您需要调整数据结构,以便只使用一次变量名称:
foreach($array as $key=>$value){
${$key} = $value;
}
这是非常劝阻的,因为它忽略了使用数组的PHP基础知识,但这可以达到你想要的目的。