How about ...

foreach ($keys as $key=>$value) $new_array[$value] = $vals[$key];

        From:  elias [SMTP:[EMAIL PROTECTED]]
        Sent:  01 August 2001 15:16
        To:  [EMAIL PROTECTED]
        Subject:  Make associative array from two arrays


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



PHP General Mailing List (
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