2012-02-10 107 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']);