ste*_*ros 3 php arrays sorting
我想用字符串键重写数组"foo"的数字键.该关系保存在另一个数组"bar"中.
$foo = array(
1 => 'foo',
2 => 'bar',
...
);
$bar = array(
1 => 'abc',
2 => 'xyz',
...
);
$result = array(
'abc' => 'foo',
'xyz' => 'bar',
...
);
Run Code Online (Sandbox Code Playgroud)
实现这一结果的最快方法是什么?
使用array_combine功能:
$combined = array_combine($bar, $foo);
Run Code Online (Sandbox Code Playgroud)
print_r($combined); 给
Array
(
[abc] => foo
[xyz] => bar
)
Run Code Online (Sandbox Code Playgroud)