Get the top value of array

Context: To give context, I am trying to create a graph with the months as the labels and the number of applications as the dataset.

My code:

$apps = Application::whereBetween('created_at', [
        Carbon::now()->startOfYear(),
        Carbon::now()->endOfYear(),
    ])
    ->get()
    ->groupBy(function ($val) {
        return Carbon::parse($val->created_at)->format('M');
    })
    ->toArray();

returns

array:3 [▼
 "Jan" => array:2 [▶]
 "Feb" => array:1 [▶]
 "May" => array:1 [▶]
]

I want to create an array that produces this result:

['Jan', 'Feb', 'May']

I have tried using array keys, values, etc without any joy.



Read more here: https://stackoverflow.com/questions/68473459/get-the-top-value-of-array

Content Attribution

This content was originally published by Paolo Resteghini at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: