Laravel collections

méthode where()

Quand est apparue cette méthode ?

depuis Laravel... heu... je vais chercher!

Description


Exemples

Il y a 1 exemple pour cette collection

Exemple #1 : Recherche simple

Collection utilisée

Code source


$languages = collect([
            "php",
            "python",
            "javascript",
            "go",
            "c#",
            "java",
            "cobol",
            "basic"
            ]);
$level = collect([
            "expert",
            "normal",
            "normal",
            "newbie",
            "newbie",
            "normal",
            "newbie",
            "expert"
            ]
        );

$languages = collect([
            ['languages' => "php", 'level' => "expert"],
            ['languages' => "python", 'level' => "normal"],
            ['languages' => "javascript", 'level' => "normal"],
            ['languages' => "go", 'level' => "newbie"],
            ['languages' => "c#", 'level' => "newbie"],
            ['languages' => "java", 'level' => "normal"],
            ['languages' => "cobol", 'level' => "newbie"],
            ['languages' => "basic", 'level' => "expert"],
            ]);

$result = $languages->where('level', 'expert');
print_r ($result);

Résultat

    
Illuminate\Support\Collection Object
(
    [items:protected] => Array
        (
            [0] => Array
                (
                    [languages] => php
                    [level] => expert
                )

            [7] => Array
                (
                    [languages] => basic
                    [level] => expert
                )

        )

)