php - Combine two arrays into keys and values in a resulting array? -
this question has answer here:
- php values of 1 array key of array 3 answers
i have 2 arrays, 1 keys , other values:
key_array = ['key1','key2','key3'] values_array = ['val1','val2','val3']
how iterate through them (their size vary) obtain this:
array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3')
use array_combine()
:
$a = array('green', 'red', 'yellow'); $b = array('avocado', 'apple', 'banana'); $c = array_combine($a, $b); print_r($c); ?> array ( [green] => avocado [red] => apple [yellow] => banana )
Comments
Post a Comment