2017-09-25 203 views
2

我想從數組中刪除鍵[屬性]像下面刪除母密鑰

我有:

Array(
[Values] => 1 
[List] => Array(
    [Product] => Array( 
     [Details] => Array( 
      [Properties] => Array( 
       [Id] => 1 
      ) 
     ) 
    ) 
) 
) 

我想刪除[特性]:

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

您可以編輯例如輸入到顯示結構時,它有一個以上的項目嗎? –

+0

在unset($ myarray ['properties'])中使用'unset()'' –

+0

@RobertRocha - 它也不起作用 – Adkidus

回答

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 
         ) 
       ) 
     ) 
)