I'm new to PHP working on script to get JSON data from a URL I got the data from the URL and decoded that JSON also.
But issue is that the JSON decoded array is not converting into String. An error comes when I try to run in to foreach loop
here is that array example output:
Array name is: $data
OUTPUT:
array(2) {
[0]=> string(5) "world"
[1]=> array(12) {
[0]=> string(15) "worldstarhiphop"
[1]=> >string(17) "world series 2014"
[2]=> string(18) "world of solitaire"
[3]=> string(9) "world map"
[4]=> string(19) "world's tallest cow"
[5]=> string(10) "world news"
[6]=> string(12) "world series"
[7]=> string(9) "worldstar"
[8]=> string(12) "world market"
[9]=> string(29) "worldstarhiphop official site"
[10]=> string(19) "world's tallest dog"
[11]=> string(17) "world of warcraft"
}
}
I tried that:
if(is_array($data)) {
foreach ($data as $key=>$value) {
echo $value;
}
}
Giving this error:
Notice: Array to string conversion in
$datais an array containing both strings and arrays. So, in one iteration of the loop,$valueis an array.is_array), then loop over it and print each element.$datais an array. I was talking about$value. Sometimes it's a string, sometimes it's an array.