RE: Make associative array from two arrays

From: Date: Wed, 01 Aug 2001 15:34:21 +0000
Subject: RE: Make associative array from two arrays
Groups: php.general 
Request: Send a blank email to php-general+get-60674@lists.php.net to get a copy of this message
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!

« previous php.general (#60674) next »