php - Combine two arrays into keys and values in a resulting array? -


this question has answer here:

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

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -