Reputation: 790
In my application i am making curl request and in response getting an array, but somehow not able to manipulate that array also is_array() not recognize that as an array.
code for curl request is :
$curls="http://localhost/myapp/alertentryxml.php?".$compurl;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$curls);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$store = curl_exec($ch);
and generating an multidimensional array from alertentryxml.php with
print_r($data);
$data is multidimensional array.
when i checked response in above $store variable, it shows an array in response but not working as a array. What i have done wrong here? is it possible to send array as a response or not?
Upvotes: 0
Views: 623
Reputation: 27618
You can't just do a print_r($data)
and expect PHP to be able to interperate this as an array, it's just text. Lookup what print_r does:
Prints human-readable information about a variable
What you should do is:
alertentryxml.php
echo json_encode($data);
and then in your curl request:
$store = json_decode(curl_exec($ch));
I've chosen JSON in this instance as it's my personal preference, but you could also send the data as XML or any other format as long as you decode it the same way it was encoded at the other end.
Upvotes: 1