Laravel collections

méthode uniqueStrict()

Quand est apparue cette méthode ?

depuis Laravel v5.3

Description


Exemples

Il y a 1 exemple pour cette collection

Exemple #1 : Différence entre unique() et uniqueStrict()

Collection utilisée

Code source



$strictCollection = collect([
    1,3,1,12,3,12,'1','12','13'
]);
echo "<h3>Used collection</h3>" . PHP_EOL;
print_r($strictCollection);
echo "<h3>With unique() only :</h3>" . PHP_EOL;
print_r($strictCollection->unique());
echo "<h3>With uniqueStrict() :</h3>" . PHP_EOL;
var_dump($strictCollection->uniqueStrict());

Résultat

    

Used collection

Illuminate\Support\Collection Object ( [items:protected] => Array ( [0] => 1 [1] => 3 [2] => 1 [3] => 12 [4] => 3 [5] => 12 [6] => 1 [7] => 12 [8] => 13 ) [escapeWhenCastingToString:protected] => )

With unique() only :

Illuminate\Support\Collection Object ( [items:protected] => Array ( [0] => 1 [1] => 3 [3] => 12 [8] => 13 ) [escapeWhenCastingToString:protected] => )

With uniqueStrict() :

object(Illuminate\Support\Collection)#1435 (2) { ["items":protected]=> array(6) { [0]=> int(1) [1]=> int(3) [3]=> int(12) [6]=> string(1) "1" [7]=> string(2) "12" [8]=> string(2) "13" } ["escapeWhenCastingToString":protected]=> bool(false) }