array_push.. wont accept ($key => "value")

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bg
Forum Contributor
Posts: 157
Joined: Fri Sep 12, 2003 11:01 am

array_push.. wont accept ($key => "value")

Post by bg »

If you can define an array as such:

Code: Select all

$blah = array(0 => "value", 1 => "value2");
why cant you use array_push in a similar fashion, for example

Code: Select all

array_push($array, 0 => "value");
What is a good work around for this?
spaace
Forum Newbie
Posts: 4
Joined: Wed Jan 28, 2004 11:46 am

Post by spaace »

I think that its because array_push is acting like a stack, which will only allow the last-in-first-out order of the data. Otherwise, array_pop would not give you back the data in the reverse order it was pushed on.

By passing a key or index it will mess this order up.
Post Reply