グループ化された配列を生成しようとしています。
これが私のコードです:
function group_assoc($array, $key) {
$return = array();
foreach($array as $v) {
$return[$v[$key]][] = $v;
}
return $return;
}
現在の出力は次のとおりです。
Array
(
[2007] => Array
(
[0] => Array
(
[sponsorID] => 4
[showType] => 2
[categoryID] => 3
[sponYear] => 2007
[sponName] => asdasd
[sponFileName] => design-desktop-wallpaper-2114754569.jpg
)
)
[2013] => Array
(
[0] => Array
(
[sponsorID] => 2
[showType] => 1
[categoryID] => 6
[sponYear] => 2013
[sponName] => Test Sponsor
[sponFileName] => Jellyfish.jpg
)
[1] => Array
(
[sponsorID] => 3
[showType] => 2
[categoryID] => 1
[sponYear] => 2013
[sponName] => asdads
[sponFileName] => Jellyfish.jpg
)
)
)
どうすればこのようなことができますか:
Array
(
[0] =>
[sponYear] => '2013'
Array
(
[0] => Array
(
[sponsorID] => 4
[showType] => 2
[categoryID] => 3
[sponYear] => 2007
[sponName] => asdasd
[sponFileName] => design-desktop-wallpaper-2114754569.jpg
)
)
[1] =>
[sponYear] => '2007'
Array
(
[0] => Array
(
[sponsorID] => 2
[showType] => 1
[categoryID] => 6
[sponYear] => 2013
[sponName] => Test Sponsor
[sponFileName] => Jellyfish.jpg
)
[1] => Array
(
[sponsorID] => 3
[showType] => 2
[categoryID] => 1
[sponYear] => 2013
[sponName] => asdads
[sponFileName] => Jellyfish.jpg
)
)
)
表示のために最初のループを実行すると、「sponYear」を表示できるようになりますか?