venabeo
venabeo

Reputation: 69

var_dump on json result produces output int(1)

This is the result which comes

{"response":1, "num":"322343434", "id":22, "again":0, "text":"xe", "branchId":0};

code

$ch = curl_init($url);
$result = curl_exec($ch);
curl_close($ch);

echo('<br><br>');
var_dump(json_decode($result));
var_dump(json_decode($result, true));

Output int(1) int(1)

I am just trying to format the result with the properties I need name and id which I would echo out.

Upvotes: 0

Views: 140

Answers (1)

tshimkus
tshimkus

Reputation: 1181

To get curl to return a string you need to include: curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

Curl is returning TRUE (or 1 in this case), which is the expected result when you do not explicitly instruct it to return the result as a string.

This line needs to be added after curl_init() and before curl_exec().

Upvotes: 3

Related Questions