title: Pass php var to curl
body: <p>I am trying to pass a php variable into a php curl script, but I am struggling.</p>
  
  <p>Any thoughts would be appreciated.</p>
  
  <pre><code>$thestring = "foobar";
  
  $data = '{"last":"$thestring"}'; //this will not work
  $data = '{"last":$thestring}'; //this will not work
  
  $data = '{"last":"foobar"}'; //this does work
  
  $url = "https://myjson.com.json"; //not my real url
  $headers = array('Content-Type: application/json');
  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, $url);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  $response = curl_exec($curl);
  curl_close($curl);
  echo $response;
  </code></pre>