RE: [PHP] Array Push and Keys
| From: | Ford, Mike [LSS] | Date: | Fri, 29 Aug 2003 15:32:08 +0000 |
| Subject: | RE: [PHP] Array Push and Keys | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-161144@lists.php.net to get a copy of this message | ||
-----Original Message-----
From: Mike Morton
To: David Otton
Look - David - I do appreciate your efforts to help - and I realize that
working blind on an email list is tough, but the question is not about
the
structure of the code, the database, reserved words or anything else.
The question for anyone out there is simple - does array_push allow you
to
push key=>value pairs?
--------------------------
No.
The manual is really clear on this one when it says array_push($array, $var)
has the same effect as $array[] = $var. Applying this to your question: if
you could do $array[] = $k=>$v then you could do array_push($array, $k=>$v),
but you can't so you can't.
Having said that, I've just given you a clue: since array_push($array, $var)
is equivalent to $array[] = $var, you can get the result you want by doing:
$array[] = array($k, $v);
(with, of course, appropriate values for $array, $k and $v substituted to
suit your code!).
Cheers!
Mike