Do the laravel collection methods (or PHP array methods, for that matter) have a way to shift off the first key/value pair of a collection?
That is, if I have the following small program
$collection = collect(['key1'=>'value1','key2'=>'value2']);
var_dump(
$collection->first()
);
var_dump(
$collection->shift()
);
I can shift()
value1
off the beginning of the collection, or grab it without removing it via first()
. What I'd like is way, with one line of code, to shift off or grab the key of the first value (i.e. key1
). I know I can do something like this
$result = (function($c){
foreach($c as $key=>$value)
{
return $key;
}
})($collection);
but I was hoping-that/wondering-if Laravel had something more elegant/compact.