我有一个像这样的PHP数组:
Array
(
[0] => Array
(
[option_id] => 21
[header_image] => logo.png
)
[1] => Array
(
[option_id] => 21
[menu1] => About
)
[2] => Array
(
[option_id] => 22
[menu2] => Speaker
)
[3] => Array
(
[option_id] => 22
[menu3] => Agenda
)
[4] => Array
(
[option_id] => 22
[menu4] => Venue
)
[5] => Array
(
[option_id] => 23
[menu5] => Hotel
)
[6] => Array
(
[option_id] => 23
[menu6] => Sponsors
)
)
我想要这样的数组:
Array
(
[0] => Array
(
[option_id] => 21
[header_image] => logo.png
[menu1] => About
)
[1] => Array
(
[option_id] => 22
[menu2] => Speaker
[menu3] => Agenda
[menu4] => Venue
)
[2] => Array
(
[option_id] => 23
[menu5] => Hotel
[menu6] => Sponsors
)
)
我想绑定具有相同option_id的数组。 我怎样才能做到这一点?
答案 0 :(得分:1)
您需要使用foreach
<?php
$output = array();
if (! empty($arr)) {
foreach ($arr as $elem) {
if (! empty($elem)) {
foreach ($elem as $k => $v) {
$output[$elem['option_id']][$k] = $v;
}
}
}
}