I have an associative array that contains academic subjects data which is :
- subjectName
- year
- semester
here is how it looks:
$subjects = array (
0 => array (
'subjectName' => 'Introduction to Programming',
'year' => '1',
'semester' => '1', ),
1 => array (
'subjectName' => 'Introduction into Computer Science',
'year' => '1',
'semester' => '1', ),
2 => array (
'subjectName' => 'Computer Architecture',
'year' => '1',
'semester' => '2', ),
3 => array (
'subjectName' => 'Statistics',
'year' => '2',
'semester' => '1', ),
4 => array (
'subjectName' => 'DBMS',
'year' => '2',
'semester' => '1', ),
);
I want to convert (modify) this array to a 3 dimension array based on the level ($subjects['level']) then the semester ($subjects['semester']).
Eventually i want it to look like this :
$newArray = array(
0 => array(
0 => array(
0 => array(
'subjectName' => 'Introduction to Programming',
'year' => '1',
'semester' => '1'
),
1 => array(
'subjectName' => 'Introduction into Computer Science',
'year' => '1',
'semester' => '1'
)
),
1 => array(
0 => array(
'subjectName' => 'Computer Architecture',
'year' => '1',
'semester' => '2'
)
)
),
1 => array(
0 => array(
0 => array(
'subjectName' => 'DBMS',
'year' => '2',
'semester' => '1'
)
)
)
);
I've messed around with array_filter() but couldn't achieve anything.
var_export()to dump the data and use copy & paste to put it in the question as text.array_filter()does not change the array structure, it just removes some items from the array. It is not the right tool for the job.