<?php
$infoArray =array(
array(
'season'=>'winter 2014',
'link'=>'link1'
),
array(
'season'=>'summer 2013',
'link'=>'link2'
),
array(
'season'=>'fall 2012',
'link'=>'link3'
),
array(
'season'=>'summer 2014',
'link'=>'link4'
),
array(
'season'=>'winter 2013',
'link'=>'link5'
)
);
$newArray =array();
$innerArray=array();
foreach ($infoArray as $info){
$season = explode(" ", $info['season']);
$seasonName = $season[0];
$seasonYear = $season[1];
if (array_key_exists($seasonYear, $newArray)) {
$newArray[$seasonYear][$seasonName]=$info['link'] ;
}
else {
$innerArray[$seasonName] = $info['link'];
$newArray[$seasonYear]=$innerArray ;
}
}
preferences:
40.77 ms | 402 KiB | 5 Q