我想从数组中删除键[Properties],如下所示
我拥有它:
Array(
[Values] => 1
[List] => Array(
[Product] => Array(
[Details] => Array(
[Properties] => Array(
[Id] => 1
)
)
)
)
)
我想删除[properties]:
Array(
[Values] => 1
[List] => Array(
[Product] => Array(
[Details] => Array(
[ID] => 1
)
)
)
)
我试过了:
$result = array_map(function($sub) { return $sub['Properties']; }, $array);
和
$array= array_column($array, 'Properties');
不幸的是它不起作用。 我怎么能这样做?
答案 0 :(得分:2)
直向前:
$arr = [
"Values" => 1,
"List" => ["Product" => [ "Details" => ["Properties" => ["Id" => 1] ] ] ]
];
$arr['List']['Product']['Details']['Id'] = $arr['List']['Product']['Details']['Properties']['Id'];
unset($arr['List']['Product']['Details']['Properties']);
print_r($arr);
输出:
Array
(
[Values] => 1
[List] => Array
(
[Product] => Array
(
[Details] => Array
(
[Id] => 1
)
)
)
)