simonp Posted February 27, 2023 Share Posted February 27, 2023 I want to add another item to the order_lines array but however I do it I end up with an error: $data = [ 'purchase_country'=>$company_country, 'purchase_currency'=>$currency_nm, 'order_amount'=>$api_amount, 'locale'=>"en-GB", 'order_tax_amount'=>0, 'order_lines'=>[ [ 'name'=>$product_name, 'quantity'=>1, 'unit_price'=>$api_amount, 'tax_rate'=>0, 'total_amount'=>$api_amount, 'total_tax_amount'=>0 ] ], "intent"=>"buy" ]; I thought this would work: 'order_lines'=>[ [ 'name'=>$product_name, 'quantity'=>1, 'unit_price'=>$api_amount, 'tax_rate'=>0, 'total_amount'=>$api_amount, 'total_tax_amount'=>0 ], [ 'name'=>$product_name2, 'quantity'=>1, 'unit_price'=>$api_amount2, 'tax_rate'=>0, 'total_amount'=>$api_amount2, 'total_tax_amount'=>0 ] ], "intent"=>"buy" ]; Any ideas please? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/315959-how-should-this-array-be-formatted/ Share on other sites More sharing options...
Barand Posted February 27, 2023 Share Posted February 27, 2023 9 minutes ago, simonp said: I end up with an error: What error are you gettiing? Quote Link to comment https://forums.phpfreaks.com/topic/315959-how-should-this-array-be-formatted/#findComment-1606075 Share on other sites More sharing options...
ginerjm Posted February 27, 2023 Share Posted February 27, 2023 (edited) You are storing calculated items in your array elements. That is not necessary when you have the details of the calc already present. How about these lines: 'order_lines'=> [ [ 'name'=>$product_name, 'quantity'=>1, 'unit_price'=>$api_amount, 'tax_rate'=>0, 'total_amount'=>$api_amount, 'total_tax_amount'=>0 ] ], You have an element with no key And - why an array and not a db? Edited February 27, 2023 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/315959-how-should-this-array-be-formatted/#findComment-1606076 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.