I have 2 arrays:
$array1 = array(1 => "aaa", 4 => "bbb", 5 => "ccc", 8 => "ddd", 9 => "eee", 11 => "fff");
$array2 = array(2 => "", 3 => "", 6 => "", 7 => "", 9 => "", 13 => "");
I want to change the keys of $array1 according to $array2. I’m given the information that an element of the second array has to correspond to another of the first one. For example I know that $array2[6] has to correspond to $array1[4].
So I should have all the keys of $array1 changed according to this rule:
$array1 = array(3 => "aaa", 6 => "bbb", 7 => "ccc", 9 => "ddd", 13 => "eee", 2 => "fff");
I don’t know how to solve this. I’ve tried to split the first array where the element given is but I’m stuck.
if you wanna update all elements of your first array with the values in the array2 in the same order :
But if you want to update according to an order you pre-defined, you have to make something else, like a table defining the rule :
Hope this helps.
Aw, you know the difference is always the same !
Then this should be something like :