user1477886
user1477886

Reputation: 263

How to convert curl_exec response to associative array?

I have the following code:

$real_result=curl_exec($ch);
echo $real_result;

I see the following result: {"result":"LOGIN","old_value":"1"} I need to convewrt $real_result to simple associative array, because I need to compare that with another array. I have tried it:

$data=json_decode($real_result);
array_intersect(json_decode($real_result), $expected_result);

But it doesn't work and I have got the message that the first argument is not an array. So, please, tell me how I can do it. Thanks.

Upvotes: 0

Views: 253

Answers (1)

xdazz
xdazz

Reputation: 160843

Set the second parameter with true to get array.

$data=json_decode($real_result, true);

Upvotes: 1

Related Questions