I try to get the key from the largest value inside an multidimensional array.
Here is my sample array
$resultCache[129] = [
'total' => 1000,
'free_from' => "2000",
'addinupshippingcosts' => "0",
'articles' => [
['shipping_costs_total' => 25], //<= i want the key of this array entry
['shipping_costs_total' => 12],
]
];
First I thought I could go for some like
foreach($resultCache as $s => $r){
$highest = array_keys(
$resultCache[$s]['articles'],
max(array_column($resultCache[$s]['articles'], 'shipping_costs_total'))
);
}
since I got inspired by
Return index of highest value in an array and Find highest value in multidimensional array.
But the result is always an empty array. I guess array_keys dont work when I use an associativ array like I tried.
Is there any other way to achive this? Of course without collecting the values by my self.