3v4l.org

run code in 300+ PHP versions simultaneously
<?php $sql = array( array( 'date_max' => '2019-12-15', 'id_property' => 18, 'last_validation' => 1 ), array( 'date_max' => '2020-08-31', 'id_property' => 18, 'last_validation' => 5 ), array( 'date_max' => '2019-12-15', 'id_property' => 21, 'last_validation' => 1 ) ); $data = []; //create array of results grouped by the property id foreach($sql as $current_key => $current_array) { $ts = strtotime($current_array['date_max']); //unix timestamp from date $data[$current_array['id_property']][$ts] = $current_array; } $maxData = []; foreach($data as $propertId=>$values) { ksort($values); //sort by key, highest value first $maxData[] = array_pop($values); //take first value } print_r($maxData);

This is an error 500

Value for `_results` contains invalid data `array`


preferences:
164.17 ms | 2065 KiB | 14 Q