将PHP进程数组转换为var-key
我已经得到了一个数组,我正在尝试解决如何通过它循环,将键指定为php变量,将值指定为php值将PHP进程数组转换为var-key,php,arrays,variables,Php,Arrays,Variables,我已经得到了一个数组,我正在尝试解决如何通过它循环,将键指定为php变量,将值指定为php值 Array ( [count] => 1 [0] => Array ( [cn] => Array ( [count] => 1 [0] => Distributed Site
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'
等等
你知道怎么做吗
谢谢您需要调整您的数据结构,以便一次且仅一次唯一地使用变量名:
foreach($array as $key=>$value){
${$key} = $value;
}
这是非常不鼓励的,因为它忽略了使用数组的PHP基础知识,但这正是您希望它做的。到目前为止您做了哪些尝试?我想您更多的是问“我应该构建什么源数组,以便以一种我可以有效访问/操作的方式为我提供所需的数据”?我无法理解你是如何得到如此混乱的数据的。你是从哪里得到的?这有助于记住下面这句话:如果eval()是答案,那么你几乎肯定问错了问题拉斯马斯·勒多夫,PHP的BDFL