I want to rewrite array “foo”‘s numeric keys with string keys. The relation is saved in another array “bar”.
$foo = array(
1 => 'foo',
2 => 'bar',
...
);
$bar = array(
1 => 'abc',
2 => 'xyz',
...
);
$result = array(
'abc' => 'foo',
'xyz' => 'bar',
...
);
What is the fastest way to achieve this result?
NullPointer’s example will fail if the keys/values in both arrays ($foo and $bar) will be in different order. Consider this:
If you run
array_combine($foo, $bar)like before, the output will beThis simple loop, however, should work: