tags:

views:

20

answers:

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?

A: 

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);
Daniel Egeberg