现在有一个数组
$arr = array("1"=>"A", "2"=>"B", "3"=>"C")
同时有个 MYSQL 语句:
SELECT id,name FROM tbl ORDER BY id
执行后得到数组:
Array
(
[0] => Array
(
[id] => 1
[name] => 小明
)
[1] => Array
(
[id] => 2
[name] => 小李
)
[2] => Array
(
[id] => 3
[name] => 小张
)
[3] => Array
(
[id] => 4
[name] => 小红
)
)
而之前那个数组 $arr 中的 key,其实就是 mysql 中的字段 id。我想把两个数组融合为:
Array
(
[0] => Array
(
[id] => 1
[name] => 小明
[rank] => A
)
[1] => Array
(
[id] => 2
[name] => 小李
[rank] => B
)
[2] => Array
(
[id] => 3
[name] => 小张
[rank] => C
)
[3] => Array
(
[id] => 4
[name] => 小红
[rank] =>
)
)
请问效率最优的写法是什么?
1
joeke 2017-08-02 09:59:26 +08:00
诶呀,我在 segmentfault 也看到了,不循环是不可能的,用 array_walk 吧
|