I have data in array and I want to get top 5 data from array and want to display in view page. My code for that function is :
public function dataStudentGraph($data) {
$labels = [];
$graph_data = [];
foreach ($data['data'] as $student) {
$labels[] = $student['name'];
$graph_data[] = $student['total'];
}
$array = [
[
'label' => 'Total Student',
'color' => '#fec12c',
'data' => $graph_data
]
];
$graph_data = [];
return [
'labels' => $labels,
'datasets' => $array
];
}
My view page code is:
<div class="ibox-content">
{!! $student_graph !!}
</div>
I want to fetch top 5 data of student['total'] in descending order. Please help.