Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

noblemfd's avatar

How to sort external API in desc order and select set of records

In my Laravel-8, I am getting external API using Guzzle:

I got this set of records for dd($json) in the Controller:

array:554 [▼
 0 => array:30 [▼
  "PartitionKey" => "19SB22"
  "RowKey" => "0000"
  "Timestamp" => "2021-01-22T12:30:25.4698261Z"
  "client_tracking_id" => "ddd3321"
  "current_asset_position_name" => "2, Adelaide, Australia"
  "service_tracking_id" => "19SB22"
  "this_tracking_job_id" => "0000"
  "trip_status" => "DISPATCHED"
]
1 => array:31 [▼
  "PartitionKey" => "19SB22"
  "RowKey" => "2233"
  "Timestamp" => "2021-02-23T20:51:50.3066741Z"
  "client_tracking_id" => "TRIP-20200621007"
  "current_asset_position_name" => "20, Adelaide, Australia"
  "service_tracking_id" => "19SB22"
  "this_tracking_job_id" => "19SB22"
  "trip_status" => "AROUND CUSTOMER LOCATION"
]
....

Here is the Controller:

public function index() {
    $client = new Client();
    $res = $client->request('GET','https://example.com/api/tracking/19SB22', [
       'query' => ['key' => 'jkkmkf']
   ])->getBody();
    $json = json_decode($res->getContents(), true);       
    return view('welcome', [
        'json' => $json,

    ]);

How do I sort the result $json in descending order using Timestamp field and select the first set of record?

Thanks

0 likes
1 reply

Please or to participate in this conversation.