Framework: array_column on collections

Created on 26 May 2016  路  3Comments  路  Source: laravel/framework

On a collection, it should be possible to do

$collection->column('id');

to get the same result as what
array_column($array, 'id');

would give you.

Currently, I have had to go by using something like this:

$uuids = $collect->map(function($category) {
    return $category->id;
});

Unless i'm missing something, there is no column method on collections?

Most helpful comment

For anyone googling around
$collection->pluck('name')->toArray();

All 3 comments

Ah, it appears that pluck does this.

Would it make sense to have an alias for pluck as column since thats what the method is called in PHP?

@shopblocks pluck makes perfect sense.

You are plucking id column out of the array and creating a new one.

For anyone googling around
$collection->pluck('name')->toArray();

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PhiloNL picture PhiloNL  路  3Comments

progmars picture progmars  路  3Comments

Fuzzyma picture Fuzzyma  路  3Comments

felixsanz picture felixsanz  路  3Comments

RachelScodes picture RachelScodes  路  3Comments