Reputation: 301
i get max value for column but i want to get also the column name of that max value
$getdata = DB::table('item')->get();
$sum=array();
foreach($getdata as $abc)
$ab = max(
$abc->jan,
$abc->feb,
$abc->mar,
$abc->apr,
$abc->may,
$abc->jun,
$abc->jul,
$abc->aug,
$abc->sep,
$abc->oct,
$abc->nov,
$abc->dec);
$sum[] = $ab;
When i Run this code
[5,2,12,1]
Here is the table
Upvotes: 0
Views: 29
Reputation: 1956
You can find the key of the highest(s) element(s) with the following code:
$maxs = array_keys($array, max($array))
You may add the $maxs
variable to the $sum
array and return it as a multidimensional array.
Upvotes: 2