Suppose, I have an array
$array1 = array(10, 20);
and another array of same values as above
$array2 = array(10, 20);
I want to combine these two arrays and generate an array with unique key and value pair. I want $array3
output to be like this:
$array3 = array(10 => 20, 20 => 10)
I tried shuffling the second array ($array2
), sometimes it gives me the same values as first one($array1
). And my $array3
output is:
$array3 = array(10 => 10, 20 => 20)
array_combine($array1, array_reverse($array2));
That will achieve the $array3
that you specified in the example you provided, but in general will not work unless $array1
and $array2
have the same number of values.
I'm a little confused about what you really need. Can you provide another example with more keys / values?