我有这个数组(var_dump()
的输出):
array (size=32)
2 => &
array (size=3)
'data' =>
array (size=3)
'parent_id' => string '1' (length=1)
'id' => string '2' (length=1)
'options' => string '2' (length=1)
'attr' =>
array (size=2)
'rel' => string 'container' (length=9)
'id' => string '2' (length=1)
'children' =>
array (size=3)
3 => &
array (size=3)
'data' =>
array (size=3)
'parent_id' => string '2' (length=1)
'id' => string '3' (length=1)
'options' => string '3' (length=1)
'attr' =>
array (size=2)
'rel' => string 'container' (length=9)
'id' => string '3' (length=1)
'children' =>
array (size=2)
8 => &
array (size=3)
'data' =>
array (size=3)
'parent_id' => string '3' (length=1)
'id' => string '8' (length=1)
'options' => string '1' (length=1)
'attr' =>
array (size=2)
'rel' => string 'container' (length=9)
'id' => string '8' (length=1)
'children' =>
array (size=2)
11 => &
array (size=3)
'data' =>
array (size=3)
'parent_id' => string '8' (length=1)
'id' => string '11' (length=2)
'options' => string '3' (length=1)
'attr' =>
array (size=2)
'rel' => string 'container' (length=9)
'id' => string '11' (length=2)
正如您所看到的,一些键是通过引用传递的,我想将此数组更改为常规数组,如下所示:
array (size=32)
0 =>
array (size=3)
'data' =>
array (size=3)
'parent_id' => string '1' (length=1)
'id' => string '2' (length=1)
'options' => string '2' (length=1)
'attr' =>
array (size=2)
'rel' => string 'container' (length=9)
'id' => string '2' (length=1)
'children' =>
array (size=3)
0 =>
array (size=3)
'data' =>
array (size=3)
'parent_id' => string '2' (length=1)
'id' => string '3' (length=1)
'options' => string '3' (length=1)
'attr' =>
array (size=2)
'rel' => string 'container' (length=9)
'id' => string '3' (length=1)
'children' =>
array (size=2)
0 =>
array (size=3)
'data' =>
array (size=3)
'parent_id' => string '3' (length=1)
'id' => string '8' (length=1)
'options' => string '1' (length=1)
'attr' =>
array (size=2)
'rel' => string 'container' (length=9)
'id' => string '8' (length=1)
'children' =>
array (size=2)
0 =>
array (size=3)
'data' =>
array (size=3)
'parent_id' => string '8' (length=1)
'id' => string '11' (length=2)
'options' => string '3' (length=1)
'attr' =>
array (size=2)
'rel' => string 'container' (length=9)
'id' => string '11' (length=2)
答案 0 :(得分:1)
$array = json_decode(json_encode($array), true);
你也可以使用这个功能。
function deReferencing($value)
{
if (is_array($value))
{
$return = array();
foreach ($value as $key => $item)
{
unset($value[$key]);
if (is_numeric($key)) {
$return[] = deReferencing($item);
} else {
$return[$key] = deReferencing($item);
}
}
}
else
$return = $value;
return $return;
}
$array = deReferencing($array);