mercredi 26 mai 2021

How to use array_push in map method in Laravel?

$ids = [1];
$collection = collect([2]);
$collection->map(function ($item) use ($ids) {
   array_push($ids, $item);
});
dd($ids);

This code returns

array:1 [ 0 => 1 ]

I thought this would return [1, 2] because of array_push;

How can I get [1, 2] or array:2 [ 0 => 1 1 => 2 ] ?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2QZBofs
via IFTTT

Aucun commentaire:

Enregistrer un commentaire