Re: [PHP] array_push but with key, value pairs

2001-04-17 Thread Dean Hall

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]




Re: [PHP] array_push but with key, value pairs

2001-04-17 Thread Joseph Blythe

Dean Hall wrote

 Instead of 'array_push', do this:
 
 $input[$key] = $val;
 
Hey thanks dean that did the trick, I was trying:

$array[] = $key . "=" . $val

which of course doesn't work hehe.

Regards

Joseph




-- 
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]




[PHP] array_push but with key, value pairs

2001-04-16 Thread Joseph Blythe

Hey all,

I was just trying to figure out something that should be quite simple 
but seems to be eluding me,

consider the following:

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

}

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 ;-)

What I am really trying to do is create a new array from the 
HTTP_POST_VARS while excluding certain fields, like Submit or the X and 
Y values from a image button.

Any ideas/suggestions are very welcomed,

Regards

Joseph,



-- 
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]




RE: [PHP] array_push but with key, value pairs

2001-04-16 Thread Peter Houchin


maybe tring this ...
$input = array();

reset ($HTTP_POST_VARS);

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

}

Peter
-Original Message-
From: Joseph Blythe [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 17, 2001 3:13 PM
To: [EMAIL PROTECTED]
Subject: [PHP] array_push but with key, value pairs


Hey all,

I was just trying to figure out something that should be quite simple 
but seems to be eluding me,

consider the following:

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

}

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 ;-)

What I am really trying to do is create a new array from the 
HTTP_POST_VARS while excluding certain fields, like Submit or the X and 
Y values from a image button.

Any ideas/suggestions are very welcomed,

Regards

Joseph,



-- 
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]




Re: [PHP] array_push but with key, value pairs

2001-04-16 Thread Joseph Blythe


Peter Houchin wrote:

 maybe tring this ...
 $input = array();
 
 reset ($HTTP_POST_VARS);
 
 while ( list($key, $val) = each($HTTP_POST_VARS) ) {
if ( $key != "Submit" )  {
array_push($input, $val);
}
 
 }


Hmm, as far as I can see this will just reset the internal pointer back 
to the start of the HTTP_POST_VAR array, I suppose this should be done   
in case I have called 'each' on the array before, but it does not answer 
my question being: I want to push the key and value into an array not 
just the value. I basically need array_push functionality but with the 
ablility to use your own index values.

I hope this is more clear.

Regards

Joseph



-- 
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]




RE: [PHP] array_push but with key, value pairs

2001-04-16 Thread Peter Houchin

what about if you assign the key to = the id (if in a data base)?

maybe like

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

-Original Message-
From: Joseph Blythe [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 17, 2001 3:40 PM
To: Peter Houchin
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] array_push but with key, value pairs



Peter Houchin wrote:

 maybe tring this ...
 $input = array();
 
 reset ($HTTP_POST_VARS);
 
 while ( list($key, $val) = each($HTTP_POST_VARS) ) {
if ( $key != "Submit" )  {
array_push($input, $val);
}
 
 }


Hmm, as far as I can see this will just reset the internal pointer back 
to the start of the HTTP_POST_VAR array, I suppose this should be done   
in case I have called 'each' on the array before, but it does not answer 
my question being: I want to push the key and value into an array not 
just the value. I basically need array_push functionality but with the 
ablility to use your own index values.

I hope this is more clear.

Regards

Joseph





Re: [PHP] array_push but with key, value pairs

2001-04-16 Thread Joseph Blythe

Peter Houchin wrote:

 what about if you assign the key to = the id (if in a data base)?
 
 maybe like
 
 while (list ($key, $val) = each ($id)) { 
  if ( $key != "Submit" )  {
 
array_push($input, $val);
}
 
 }
 
I am not using a database for this part as I am just collecting the data 
to validate. I really want to know how to create a new array in a while 
loop, which contains the key and value pairs of the array passed to 
each. So lets say the above code would output:

0 = value1
1 = value2
2 = value 3
4 = value4

But I want to create:

keyname1 = value1
keyname2 = value2
keyname3 = value3
keyname4 = value4

Does anyone understand what I am on about?

Regards,

Joseph



-- 
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]