I want to create a nested array in php. The structure of the array I am trying to create
array(
'year' => 2017
'month' => array(
'0' => 'December',
'1' => 'December',
)
)
I am trying to create this array dynamically using array_push() function.
$date=array();
foreach ($allPosts as $p) {
$year=date("Y", strtotime($p['published']));
$month=date("F", strtotime($p['published']));
array_push($date, $year);
array_push($date['month'], array($month));
}
This don't work and it shouldn't :). But How can I achieve the structure dynamically.
Thank you.
array_push()to create associative arrays.