mercredi 24 août 2016

Laravel 5.2 Push onto deeper indexed arrays within a Collection

Is there a way to put/merge on changes to a deeper index on a collection without converting the collection to an array first?

I have a $collection with 4 indices that all contain $arrays so in order to push onto the arrays I have to do this:

$collection = $collection->toArray();
array_push($collection[$index], $array);

But, I was hoping there was a better way so I didn't have to re-collect(...) the original $collection before moving on, something like below, which I know wouldn't work, but forms an example of something less awkward then above:

$collection->get($index)->merge($array);



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire