3v4l.org

run code in 300+ PHP versions simultaneously
<?php public function add(Request $request) { $cart_array = Session::get('products-cart'); $newProduct = ['id' => $request->product_id, 'qty' => $request->product_qty]; $found = false; foreach($cart_array as &$item) { if ($item['id'] == $newProduct['id']) { $item = $newProduct; $found = true; } } if ($found){ Session::push('products-cart', $cart_array); } else{ array_push($cart_array, $newProduct); Session::push('products-cart', $cart_array); } return redirect()->back(); }
Output for 8.0.0 - 8.0.3
Parse error: syntax error, unexpected token "public", expecting end of file in /in/BJGg0 on line 3
Process exited with code 255.
Output for 7.3.0 - 7.3.27, 7.4.0 - 7.4.16
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting end of file in /in/BJGg0 on line 3
Process exited with code 255.

preferences:
166.82 ms | 1004 KiB | 7 Q