Laravel has collections which makes this really easy! So let's say you have your array here
$array = [
'subjects' => [
0 => [
'id' => 4,
'name' => 'abc',
'type' => 'arts',
],
// More data here
],
'students' => [
0 => [
'course_id' => 19,
'subject_number' => 30,
'subject_name' => 'Season 30',
'start_year' => 2006,
'end_year' => 2009,
],
1 => [
'course_id' => 196,
'subject_number' => 31,
'subject_name' => 'Season 31',
'start_year' => 2007,
'end_year' => 2010,
],
// More data here
],
];
// Make a collection from the students
$collection = collect($array['students']);
// Order them by the given field
// Each item is an array item of the "students" array
$collection->sortBy(function ($item) {
return $item['start_year'];
});
// Convert the collection back to an array
$sortedArray = $collection->all();
Documentation: https://laravel.com/docs/5.7/collections#method-sortby
Let me know if this works for you!