2013-04-02 73 views
0

我有以下陣列:如何將數組轉換爲一維從多維關聯在PHP中?

Array 
(
    [14] => Array 
     (
      [nid] => 30698 
      [changed] => 15 
     ) 

    [13] => Array 
     (
      [nid] => 30697 
      [changed] => 14 
     ) 

    [12] => Array 
     (
      [nid] => 30601 
      [changed] => 13 
     ) 

    [11] => Array 
     (
      [nid] => 30807 
      [changed] => 12 
     ) 

    [10] => Array 
     (
      [nid] => 30806 
      [changed] => 11 
     ) 

    [9] => Array 
     (
      [nid] => 30808 
      [changed] => 10 
     ) 

    [8] => Array 
     (
      [nid] => 30826 
      [changed] => 9 
     ) 

    [7] => Array 
     (
      [nid] => 30828 
      [changed] => 8 
     ) 

    [6] => Array 
     (
      [nid] => 30839 
      [changed] => 7 
     ) 

    [5] => Array 
     (
      [nid] => 30838 
      [changed] => 6 
     ) 

    [4] => Array 
     (
      [nid] => 30837 
      [changed] => 5 
     ) 

    [3] => Array 
     (
      [nid] => 30831 
      [changed] => 4 
     ) 

    [2] => Array 
     (
      [nid] => 30830 
      [changed] => 3 
     ) 

    [1] => Array 
     (
      [nid] => 30827 
      [changed] => 2 
     ) 

    [0] => Array 
     (
      [nid] => 30832 
      [changed] => 1 
     ) 

) 

我要隱蔽它喜歡:

陣列

(
    [14] => [changed] => 15 

    [13] => [changed] => 14 

    [12] => [changed] => 13 

    [11] => [changed] => 12 

    [10] => [changed] => 11 

    [9] => [changed] => 10 

    [8] => [changed] => 9 

    [7] => [changed] => 8 

    [6] => [changed] => 7 

    [5] => [changed] => 6 

    [4] => [changed] => 5 

    [3] => [changed] => 4 

    [2] => [changed] => 3 

    [1] => [changed] => 2 

    [0] => [changed] => 1 

) 

我能爲這個做什麼?

+1

你試過了什麼?我們不在這裏爲你做你的工作!也不能取代_imagination_。 –

+1

您的結果數組仍然會以您所展示的方式呈現多維。所以你基本上只想去掉'nid'的值? –

回答

0

您可以簡單地通過array_map()函數運行它來去除nid值。

$result_array = array_map(function ($item) { 
    unset $item['nid']; 
    return $item; 
}, $input_array);