比方说,我有以下阵列:
Array
(
[0] => Array
(
[id] => 5
[name] => Education
)
[1] => Array
(
[id] => 4
[name] => Computers
)
[3] => Array
(
[id] => 7
[name] => Science
[4] => Array
(
[id] => 1
[name] => Sports
)
)
而第二个:
Array
(
[0] => Array
(
[id] => 1
[title] => Sport
)
[1] => Array
(
[id] => 7
[title] => Sci
)
[3] => Array
(
[id] => 4
[title] => Comp
[4] => Array
(
[id] => 5
[title] => Edu
)
)
和期望的输出是:
Array
(
[0] => Array
(
[id] => 5
[name] => Education
[title] => Edu
)
[1] => Array
(
[id] => 4
[name] => Computers
[title] => Comp
)
[3] => Array
(
[id] => 7
[name] => Science
[title] => Sci
[4] => Array
(
[id] => 1
[name] => Sports
[title] => Sport
)
)
我已成功地用简单的合并这些阵列:
foreach($first as $key => $value){
$result[$key] = array_merge($first[$key], $second[$key]);
}
但输出不正确组合:
Array
(
[0] => Array
(
[id] => 5
[name] => Education
[title] => Sport
)
[1] => Array
(
[id] => 4
[name] => Computers
[title] => Sci
)
[3] => Array
(
[id] => 7
[name] => Science
[title] => Comp
[4] => Array
(
[id] => 1
[name] => Sports
[title] => Edu
)
)
问题是我想在同一个合并这些阵列id
。 期望的输出排序应当与第一阵列英寸
我怎样才能做到这一点? 任何帮助深表感谢。