1

Let's say I have an array, and I print it:

  print_r($myArray);
  Array
  (

        [post] => 333434kj
        [test] => wOVvc
        [tytytyty] => xyzsalasjf

  )

This array gets assigned to a CURL Post:

curl_setopt($ch, CURLOPT_POSTFIELDS, "field1=".$f1."&field2=".$f2."&something=True");

Since "field1" is equal to "post" and $f1 is equal to "333434kj", etc., I am having a hard time figuring out how to implement the keys and values as variables, as the [post], [test], and [tytytyty] change values for every time this runs. How do I make each key a variable and each value a variable?

1 Answer 1

1

Have a look at http://php.net/http_build_query

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($myArray) . "&something=True");

You can also just pass the array instead if you wish:

$myArray['something'] = 'True';
curl_setopt($ch, CURLOPT_POSTFIELDS, $myArray);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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