Re: Make associative array from two arrays
| From: | elias | Date: | Thu, 02 Aug 2001 07:25:38 +0000 |
| Subject: | Re: Make associative array from two arrays | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-60849@lists.php.net to get a copy of this message | ||
same same...
Thought there was a PHP function to do that...instead of looping,
"Tim Ward" <tim.ward@stivesdirect.com> wrote in message
news:D2AC2CC91E72D511BD5600500416D3C0068BFF@hunters-mail.itnetadmin.com...
> How about ...
>
> foreach ($keys as $key=>$value) $new_array[$value] = $vals[$key];
>
>
> Tim
> ----------
> From: elias [SMTP:elias_bachaalany@yahoo.com]
> Sent: 01 August 2001 15:16
> To: php-general@lists.php.net
> Subject: Make associative array from two arrays
>
> Hello!
>
> I have two arrays:
>
> $keys = array("a", "b", "c", "d");
> $vals = array(1, 2, 3, 4);
>
> I would like to get an associative array holding this:
> $aarray = array("a" =>1, "b"=>2, "c"=>3,
> "d"=>4);
>
> I know I can do it with a "while" loop...but I wonder if there is
> any
> builtin PHP function that can do that.
> Or a better method other than sort of this:
>
> $aarray = array();
> for ($i=0;$i<count($keys);$i++)
> {
> $aarray[$keys[$i]] = $vals[$i];
> }
>
> thanks!
>
>