how to sort a number of arrays of objects inside a foreach?

Place an usort function after the first iteration’s start point and you will get the sorted bookTimes in the second iteration.

<div class="row">

@if(!empty($Service) && count($Service))

@foreach($Service['result'] as $value)


usort( $value, function ( $a, $b )
//$b should come first as you want to sort in descending order
return $b['bookedTimes'] <=> $a['bookedTimes'];

@foreach($value as $val)

<div class="col-lg-12 col-md-12"><h4>Data Not Found! </h4> </div>

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top