phparraysstringkeyassociative-array

Combine two string arrays into an associative array


I have two arrays. Like:

Bear, prince, dog, Portugal, Bear, Clown, prince, ...

and a second one:

45, 67, 34, 89, ...

I want to turn the string keys in the first array into variables and set them equal to the numbers in the second array.

Is it possible?


Solution

  • extract(array_combine($arrayKeys, $arrayValues));
    

    http://php.net/array_combine
    http://php.net/manual/en/function.extract.php

    I'd recommend you keep the values in an array though, it's rarely a good idea to flood your namespace with variable variables.