• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

How to KeyBy where multiple items have the same key

phplaravellaravel-5.1


PHP Snippet 1:

$countriesById = collect($allCountries)->groupBy('id');

PHP Snippet 2:

$filtered = $allCountries->filter(function ($item) use ($id) {
    return $item->id == $id;
});

$filtered->all();

Related Snippets

Passing a boolean value from checkbox in Laravel form

IlluminateDatabaseQueryException could not find driver [duplicate]

Correct way to use LIKE '%{$var}%' with prepared statements?

What's the net::ERR_HTTP2_PROTOCOL_ERROR about?

Update Order custom Field value with WooCommerce REST API

woocommerce change position of price

PHP to search within txt file and echo the whole line

Facebook API, get page post link (PHP)

Limit WooCommerce products in cart only from one custom taxonomy

Yii2: How do I debug console commands?

Laravel phpunit test failing authorization

Transpose csv file data [duplicate]

How to Generate PDF invoice to XML format using mPDF

Laravel Factory not calling callback 'afterCreating'

Remove categories with all childs derived from parent category

About Contact Privacy policy Terms and conditions