When making a curl post to another script, sometimes I may want to send null as the value for certain keys:
$postdata = array(
'userID' => 0,
'questionText' => "Can you answer this question?",
'time' => null);
$req = curl_init($url);
curl_setopt($req, CURLOPT_POST, true);
curl_setopt($req, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($req, CURLOPT_RETURNTRANSFER, false);
curl_setopt($req, CURLOPT_VERBOSE, true);
$data = curl_exec($req);
curl_close();
However, the data seems to have changed by the time it is received. Doing a vardump on $_POST reveals that the 'time' value is now an empty string:
array(3) {
["userID"]=>
string(1) "0"
["questionText"]=>
string(29) "Can you answer this question?"
["time"]=>
string(0) ""
}
What's going on here? Why is everything a string? How can I perserve the typing?
userID=0&questionText=Can you answer this question?&time=