Created
February 21, 2019 19:04
-
-
Save TiagoSilvaPereira/c83d2a692f6183932c08726978e98d3a to your computer and use it in GitHub Desktop.
Laravel Collection - Problema com filter() e chaves de arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$collection = collect(['um', 'dois', 'tres', 'quatro', 'cinco']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$items = $collection->filter(function($item) { | |
return $item != 'um' && $item != 'quatro'; | |
})->toArray(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$items = $collection->filter(function($item) { | |
return $item != 'um' && $item != 'quatro'; | |
}) | |
->values | |
->all() | |
->toArray(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1 => 'dois', 2 => 'tres' , 3 => 'cinco'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment