Skip to content
Advertisement

Running a foreach loop within a Curl function

I need to run a foreach loop within a curl command but can’t quite get the syntax right. I’ve parsed other variables into it fine but it’s just formatting my array to fit.

JavaScript

This is my array:

JavaScript

I need to push my array into this part specifically:

JavaScript

This is my attempt but this is causing all kinds of issues, where am I going wrong?

JavaScript

Slight addition, what if the array was this and I didn’t target it with foreach($parcels[0] as $item) { but it was foreach($parcels as $item) { instead?

JavaScript

Advertisement

Answer

You can’t just put PHP code in string and expect it to be executed. You must transform your array, and then pass to cUrl:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement