Home > Mobile >  How to push object inside array laravel php?
How to push object inside array laravel php?

Time:11-30

I'm trying to define an array and add elements to it, but there's a problem with that

        $prodectsum =  array();

               $prodectsum->push((object)['name' => 'mmm', 'color' => 'red']);

Define an array in Laravel

CodePudding user response:

You can use Arr::add() or Arr::set() from Laravel Helpers. See https://laravel.com/docs/9.x/helpers#method-array-add

CodePudding user response:

$newArray = array()
$newArray[] = $someObject;
  • Related