PASSWORD RESET

Your destination for complete Tech news

How to flip keys with values in Laravel collection?

725 0
< 1 min read

To flip the keys with the values in a Laravel collection, you can use the flip method. This method will create a new collection with the keys and values swapped.

Here’s an example:

$collection = collect(['name' => 'bob', 'job' => 'developer']);
$flipped = $collection->flip();

// $flipped = ['bob' => 'name', 'developer' => 'job']

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.