Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array_column on collections #13717

Closed
shopblocks opened this issue May 26, 2016 · 3 comments
Closed

array_column on collections #13717

shopblocks opened this issue May 26, 2016 · 3 comments

Comments

@shopblocks
Copy link

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?

@shopblocks
Copy link
Author

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?

@morloderex
Copy link
Contributor

@shopblocks pluck makes perfect sense.

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

@chriscalip
Copy link

chriscalip commented Jun 6, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants