user16133750
user16133750

Reputation: 23

How to put loop array inside another array

line 1:

"item_details" => array(
            array(
                 $item_details,
            ),                
        ),

line2:

$item_details;
    foreach(Cart::content() as $item)
    {
        $item_details = array_push(
            array (
                'id' => $item->id,
                'name' => $item->name,
                'quantity' => $item->qty,
                'price' => $item->price,
            ),
        );                  
    }

What I try to do is, I want line 1 to have a dynamic array content, but after running the code I got error:

Cannot pass parameter 1 by reference

Upvotes: 2

Views: 95

Answers (1)

ParisaN
ParisaN

Reputation: 2092

$item_details = array_push(...) is not true. You have to use array_push like this, Try this:

foreach(Cart::content() as $item)
    {
       array_push($item_details, 
           [
              'id' => $item->id,
              'name' => $item->name,
              'quantity' => $item->qty,
              'price' => $item->price,
            ]);                   
    }

Upvotes: 1

Related Questions