Re: trouble with arrays (part 2)...
| From: | Ignacio Vazquez-Abrams | Date: | Mon, 27 Nov 2000 18:09:27 +0000 |
| Subject: | Re: trouble with arrays (part 2)... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-27413@lists.php.net to get a copy of this message | ||
On Mon, 27 Nov 2000, Christian Dechery wrote:
> I'm having trouble understanding arrays in PHP... can someone help me???
> Take a look...
>
> Code 1:
> $req_array;
> foreach($HTTP_POST_VARS as $field => $value)
> {
> $req_array[]["name"]=$field;
> $req_array[]["value"]=$value;
> }
>
> Code 2:
> $req_array;
> $i=0;
> foreach($HTTP_POST_VARS as $field => $value)
> {
> $req_array[$i]["name"]=$field;
> $req_array[$i]["value"]=$value;
> $i++;
> }
>
> in Code 1 the array isn't exactly filled like I want it to... it's
> something like this (I guess)
> $req_array[0][name] will contain somethin
> $req_array[0][value] will not even exist
> $req_array[1][name] will not exist
> $req_array[2][name] will contain something
> $req_array[3][value] will contain something... (I guess... I didn't exactly
> did reverse-engineering on that to see how it works [ debuging in PHP is
> not as easy as in C ])..
>
> in Code 2 the array is filled exactly the way I want it to... but I have to
> use an index... and that leads me to this question: is it possible to use
> the '[]' thing for my "Code 1" purposes? how?
>
> thanks...
> ____________________________
> . Christian Dechery (lemming)
> . http://www.tanamesa.com.br
> . Gaita-L Owner / Web Developer
>
Try:
$req_array[]=Array("name" => $field, "value" => $value);
--
Ignacio Vazquez-Abrams <ignacio@openservices.net>