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

[10.x] Add Arr::mapWithKeys() #47000

Merged
merged 4 commits into from
May 9, 2023

Conversation

ralphjsmit
Copy link
Contributor

@ralphjsmit ralphjsmit commented May 9, 2023

Personally I use the Collection mapWithKeys() method a lot. It does happen quite often still that I have just an array and need to return only an array. Converting to a collection, mapping with the keys and converting back to an array does not feel right if we have special Arr class for such array-only operations.

This PR adds the mapWithKeys() function to the Arr class.

public function getSomething(): array
{
    $data = [/** */];

    return Arr::mapWithKeys($data, function($x): array {
       // return [$y => $z]
    });
}

Thanks!

@taylorotwell taylorotwell merged commit 46ff808 into laravel:10.x May 9, 2023
milwad-dev pushed a commit to milwad-dev/framework that referenced this pull request May 12, 2023
* Add `Arr::mapWithKeys()`

* Code style

* Code style

* Code style
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

Successfully merging this pull request may close these issues.

2 participants