phparrays

Merging two flat arrays by keys into an associative array


There are 2 arrays, the reason for 2 arrays is because of 2 drop down from form post.

array1
1 => 878
2 => 983
3 => 717

array2
1 => 10
2 => 15
3 => 12

I have to loop 2 arrays and get where the keys matched and combine them into an array.

878 => 10
983 => 15
717 => 12

Solution

  • using the array_combine. try it here

    $combined = array_combine(array_values($array1),array_values($array2));