I need to combine two arrays, the key from the first array should be replaced with the respective value from the second array. The following code works fine if both arrays have the same number of elements and if they have the same order.
$first = array("a"=>"red", "b"=>"green", "c"=>"blue");
$second = array("a"=>"sun", "b"=>"grass", "c"=>"sky");
$new = array_combine($second, $first);
print_r($new);
Result
Array
(
[sun] => red
[grass] => green
[sky] => blue
)
But I need this to work in a scenario where they don´t have the same elements number or not in the same order. How can I achieve it?