2017-05-25 73 views
0

我有這樣的陣列多組多維

Array 
(
    [0] => Array 
    (
    ) 

[1] => Array 
    (
     [wpcf-fields-checkboxes-option-1a38bb558a59802a54ebd4b27c91431e-1] => Array 
      (
       [0] => Attacco rapido 
      ) 

     [wpcf-fields-checkboxes-option-0ad0b877a16a24fc4958374f171ef112-1] => Array 
      (
       [0] => Bordo bianco 
      ) 

    ) 

[2] => Array 
    (
     [wpcf-fields-checkboxes-option-1a38bb558a59802a54ebd4b27c91431e-1] => Array 
      (
       [0] => Attacco rapido 
      ) 

     [wpcf-fields-checkboxes-option-3b2241533b2c56891d3fd57718409b85-1] => Array 
      (
       [0] => Supporti regolabili 
      ) 

    ) 

我怎麼可以得到唯一值(Attacco RAPIDO,波爾多比安科,Attacco RAPIDO,Supporti regolabili)陣列?

回答

5

使用array_walk_recursive和通過引用傳遞$list由新的值來填充它

array_walk_recursive($array, function ($value, $key) use (&$list) { 
    $list[] = $value; 
}); 

print_r($list); 

輸出: -

Array (
    [0] => Attacco rapido 
    [1] => Bordo bianco 
    [2] => Attacco rapido 
    [3] => Supporti regolabili 
) 

現場演示:https://3v4l.org/uhGlk