array_sum return 0. How do I sum my array?

  arrays, laravel, laravel-8, php

I have this

        foreach ($item_id as $key => $no) {
            $input['price'] = $price[$key]['price'];
            $input['quantity'] = $quantity[$key];
            $subtotal[] = [$input['price']*$input['quantity']];
        }
        $total_price = array_sum($subtotal);

When I dd($total_price) it return 0.

When I dd($subtotal) it return my array like this

array:3 [▼
  0 => array:1 [▼
    0 => 3000000
  ]
  1 => array:1 [▼
    0 => 3
  ]
  2 => array:1 [▼
    0 => 9
  ]
]

How do I sum my array from that? Thanks!

Source: Laravel

Leave a Reply