php - Laravel Collection keys modification -
i use filter
method collection
class remove objects collection. after operation, objects keys eg. 1, 4, 5 left. have elements order 0, 1, 2, 3 etc. after filter
action.
is there elegant way without rewriting table new one?
thanks!
you can use laravel collection's values()
method make the keys of collection in serialized order this:
// demonstration $collection = collect([ 10 => ['fruit' => 'apple', 'price' => 200], 11 => ['fruit' => 'mango', 'price' => 500] ]); $values = $collection->values(); $values->all(); /* result be: [ 0 => ['fruit' => 'apple', 'price' => 200], 1 => ['fruit' => 'mango', 'price' => 500], ] */
hope helps!
Comments
Post a Comment