2012-02-10 172 views
1

我有一個數組結構是這樣的:在PHP中刪除父數組鍵?

Array (

    [donate] => Array 

    (
     [amount_other] => 222 

     [pay_method] => Array 
      (
       [5] => Array 
        (
         [first_name] => sam 
         [last_name] => indi 
         [cc_type] => mc 
         [cc_number] => 5123456789
         [cc_ccv2] => 111 
         [cc_exp_month] => 10 
         [cc_exp_year] => 20 
        ) 

      ) 

     [notes] => Test comment. 
    ) 

我想刪除鍵[5]從陣列,從而使新的數組變爲:

Array 

[donate] => Array 

    (
     [amount_other] => 222 
     [pay_method] => Array 

      (
       [first_name] => sam 
       [last_name] => indi 
       [cc_type] => mc 
       [cc_number] => 5123456789
       [cc_ccv2] => 111 
       [cc_exp_month] => 10 
       [cc_exp_year] => 20 
      ) 

     [notes] => Test comment. 
    ) 

我想這是因爲數組鍵改變了,我想直接訪問內部數組,所以我不必每次都在代碼中更改鍵。如果有其他方法可以實現這一點..請幫助。 在此先感謝。

回答

4
$array['donate']['pay_method'] = current($array['donate']['pay_method']); 
3
$array['donate']['pay_method'] = array_shift($array['donate']['pay_method']);