Skip to content

Instantly share code, notes, and snippets.

@TiagoSilvaPereira
Created February 21, 2019 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TiagoSilvaPereira/c83d2a692f6183932c08726978e98d3a to your computer and use it in GitHub Desktop.
Save TiagoSilvaPereira/c83d2a692f6183932c08726978e98d3a to your computer and use it in GitHub Desktop.
Laravel Collection - Problema com filter() e chaves de arrays
<?php
$collection = collect(['um', 'dois', 'tres', 'quatro', 'cinco']);
<?php
$items = $collection->filter(function($item) {
return $item != 'um' && $item != 'quatro';
})->toArray();
<?php
$items = $collection->filter(function($item) {
return $item != 'um' && $item != 'quatro';
})
->values
->all()
->toArray();
[1 => 'dois', 2 => 'tres' , 3 => 'cinco']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment