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

Wildcards in a hosts file

I want to setup my local development machine so that any requests for *.local are redirected to localhost . The idea is that as I develop multiple sites, I can just add vhosts to Apache called site1.local , site2.local etc, and have them all resolve to localhost , while Apache serves a different site accordingly.