2012-09-02 112 views
0

我正在努力讓這種情況發生的..也許有人知道我怎樣才能做到這一點我只做到了一部分,我也期待在PHP和Drupal功能多維數組拼合

enter image description here

這裏是全圖像

http://imageshack.us/photo/my-images/405/array.png/

filed_new(ARR ...)有可能成爲[ '值'] =串(11111)

+0

請嘗試以文本形式而不是圖像添加實際輸出。這就是說,我只能看到'filed_new(Arr ...)'在你的輸出中沒有。那麼,你只是想刪除它嗎? – DavChana

+0

filed_new(Arr ...)必須變成['value'] = string(11111) –

回答

1

您輸入數組:

... 
0{ 
    data{ 
     nid => 1 
     vid => 1 
     type => article 
     field_new{ 
      und{ 
       0{ 
        value => 11111 
       } 
      } 
     } 
    } 
} 
1{ 
    data{ 
     nid => 2 
     vid => 2 
     type => article 
     field_new{ 
      und{ 
       0{ 
        value => 33333 
       } 
      } 
     } 
    } 
} 

你期望的數組:

... 
0{ 
    data{ 
     nid => 1 
     vid => 1 
     type => article 
     value => 11111 
    } 
} 
1{ 
    data{ 
     nid => 2 
     vid => 2 
     type => article 
     value => 33333 
    } 
} 

Unset (http://php.net/manual/en/function.unset.php)是我們的朋友。

unset()銷燬指定的變量。

使用此代碼:

<?php 

$loop_count = count($input_arr); 
for($i=0;$i<loop_count;$i++){ 
    //copy the value to the desired place 
    $input_arr[$i]["data"]["value"] = $input_arr[$i]["data"]["field_new"]["und"][0]["value"]; 

    //delete the unwanted portion 
    unset($input_arr[$i]["data"]["field_new"]); 
} // for loops ENDS 

?> 

假設:

  • 你的鹼/父陣列是數字索引。
  • 在每個數組中,field_new處於同一級別。

請添加您使用您生成/獲取此數組的代碼,並且我們可以爲您提供更具體的答案。

+0

謝謝'$ arr [$ i] [「data」] [「value」] = $ arr [$ i] [「data 「] [」field_new「] ['und'] ['0'] [」value「];'工作而不是'$ input_arr [$ i] [」data「] [」value「] = $ input_arr [$ i ] [「data」] [「field_new」] [「value」];'但是,再次感謝我一直在尋找這個整個早上:) –

+0

@punked對不起,我的壞!更新了答案:) – DavChana