print array value using foreach loop in php

print array value using foreach loop in php

To print json converted array data in php we need to us loop. Because there are N number of data available in json file. So, now let's see how to print json converted array data using foreach loop in php. First of all we need to decode json data into array data to print all the data in a proper format. So follow below steps as well.

Follow below steps for print array in php :

    1. decoding json data into array

$response=json_decode($response); //decode json data into array

    2. print array value using foreach loop

 As example i have following data in array :
 Array([0]object([id]=>123[name]=>Sharma[dob]=>28/07/1989)[1]object([id]=>1234[name]=>Modi[dob]=>22/02/1979))

To print above array values i can use foreach loop please follow below code:

 foreach ($response as $result)
echo $result->id;
echo $result->name;
echo $relust->dob;


Output of above code like :
       123Sharma28/07/1989
       1234Modi22/02/1979

Explanation: decode json data into a variable called "$response" and then use foreach loop for getting data. if you want to do proper formating using HTML/CSS you can do as well.

If you are getting problem with coverted api data into array then also read :

That’s all. If you find this article is helpful don’t forget to share with your friends. Please help us by doing comment using comment box. Thank you!


Also Read:

Different type of select query in SQL

Post Comments(0)

Leave a reply