skip to Main Content

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

2

Answers


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

    Login or Signup to reply.
  2. $newArray = array()
    $newArray[] = $someObject;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search