I have a PHP array that is filled like so:
[
{"soldPrice":"228.96","dateSold":"05\/22\/2020"},
{"soldPrice":"204.99","dateSold":"06\/22\/2020"},
{"soldPrice":"399.99","dateSold":"08\/12\/2020"},
{"soldPrice":"350.00","dateSold":"08\/23\/2020"}
]
I was able to find the max by doing max($arr);, but now I added the dateSold. How can I find the min/max of this array, but also get the date that it sold?
It would echo 06/22/2020: 204.99 for min.
It would echo 08/22/2020: 399.99 for max.
I tried to add a function like this just to get the max.
function max_attribute_in_array($data_points, $value='soldPrice'){
$max=0;
foreach($data_points as $point){
if($max < (float)$point->{$value}){
$max = $point->{$value};
}
}
return $max;
}
$max = max_attribute_in_array($mainResponse);
var_dump($max);
but this was a no go.
This just returned int(0)
max(array_column($data_points, $value)).