Joseph.

"Joseph Blythe" <[EMAIL PROTECTED]> wrote:
...
> Ok fine, I now have an associative array with a numeric index, but
> hangon I wanted to push the key => value into the array. How would I do
> this, I have tried a couple of things but am having some really crazy
> results ;-)

'array_push' is only useful for numerically-indexed arrays. It's basically a
shortcut for getting the length of the array and putting a value in the last
available spot in an array. It treats the array like a stack.

In an associative array (or hash), the array is indexed by strings, so the
order you input them in is irrelevant (for the most part). I think in PHP
you can actually retrieve the values in the same order as you put them in,
but this does not have to be the case. Hash keys should be arbitrarily
ordered.

> $input = array();
> while ( list($key, $val) = each($HTTP_POST_VARS) ) {
>   if ( $key != "Submit" )  {
>   array_push($input, $val);
>   }
> }

Instead of 'array_push', do this:

$input[$key] = $val;

Dean
http://hall.apt7.com





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to