merging values from 2 arrays in to key => value in one array

Hi all,

At the moment I have two arrays, e.g. -
Array_a( ‘a_key1’ => ‘a_value1’, 'a_key2 => ‘a_value2’ );
Array_b( ‘b_key1’ => ‘b_value1’, 'b_key2 => ‘b_value2’ );

I am trying to make these in to one array where the values from Array_a are the keys and the values from Array_b are the values, e.g. -
Array_c( ‘a_value1’ => ‘b_value1’, ‘a_value2’ => ‘b_value2’ );

Trouble is the only way I know to iterate through an array is by using ‘foreach’, so I’m really struggling.

Any help would be greatly appricated.


here you go dude. This will do it.

[php]$one = array(‘a_key1’ => ‘a_value1’, ‘a_key2’ => ‘a_value2’);
$two = array(‘b_key1’ => ‘b_value1’, ‘b_key2’ => ‘b_value2’);
$three = array_merge($one, $two);[/php]

look at this here to see what array_merge is doing.

Sponsor our Newsletter | Privacy Policy | Terms of Service