Skip to main content

Remove the parent array key in PHP?



I have an array structure like this :







Array (



[donate] => Array



(

[amount_other] => 222



[pay_method] => Array

(

[5] => Array

(

[first_name] => sam

[last_name] => indi

[cc_type] => mc

[cc_number] => 5123456789012346

[cc_ccv2] => 111

[cc_exp_month] => 10

[cc_exp_year] => 20

)



)



[notes] => Test comment.

)







)





I want to remove key [5] from the array, so that the new array becomes :







Array







(







[donate] => Array



(

[amount_other] => 222

[pay_method] => Array



(

[first_name] => sam

[last_name] => indi

[cc_type] => mc

[cc_number] => 5123456789012346

[cc_ccv2] => 111

[cc_exp_month] => 10

[cc_exp_year] => 20

)



[notes] => Test comment.

)







)





I want this because the array key changes and I want to access the inner array directly so that I don't have to change the key each time in the code. If there are other ways to achieve this.. Please help. Thanks in advance.


Comments

  1. $array['donate']['pay_method'] = current($array['donate']['pay_method']);

    ReplyDelete
  2. $array['donate']['pay_method'] = array_shift($array['donate']['pay_method']);

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?