1

How to resolve this issues: Trying to access array offset on value of type int?

PHP8

    public function processPayment(Request $request)
{      
     $orders = $request->get('order');
     $ordersArray = [];

     // getting orders details
     foreach($orders as $order)
     {
         if($order['id'])
         {
             $ordersArray[$order['id']]['order_id'] = $order['id'];
             $ordersArray[$order['id']]['quantity'] = $order['quantity'];

         }
         ddd($ordersArray);
     }
9
  • You can view this answer that can help you stackoverflow.com/q/70505377/5661396 Commented Apr 22, 2022 at 8:09
  • On which line?.. Commented Apr 22, 2022 at 8:11
  • You should provide us information about where the error occurs Commented Apr 22, 2022 at 8:18
  • Asker should provide information about where the error occurs Commented Apr 22, 2022 at 8:19
  • geertjanknapen the errors occurs in this line: $ordersArray[$order['id']]['order_id'] = $order['id']; $ordersArray[$order['id']]['quantity'] = $order['quantity']; Commented Apr 22, 2022 at 8:29

1 Answer 1

3

I resolved my own problem using in this way: if(isset($order['id'])) before I did in this way:if($order['id'])

Sign up to request clarification or add additional context in comments.

1 Comment

!empty($order['id']) will do both in one go.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.