Posted inphp

How to Decode JSON Data in PHP?

Today, We want to share with you json decode php.In this post we will show you php json foreach key => $value, hear for php get json data from api we will give you demo and example for implement.In this post, we will learn about Create JSON with json_encode and json_decode using PHP with an example.

PHP json_decode() Function

here you can learn all about JSON Handling with PHP: How to Encode, Write, Parse, Decode and Convert.
JSON Functions

Function Libraries
json_encode Returns the JSON representation of a value.
json_decode Decodes a JSON string.
json_last_error Returns the last error occurred.

Example 1:

Example 2: access the values from the PHP object:

echo $obj->Rohit;
echo $obj->Jasmrit;

Example 3: access the values from

json_decode to array

$result = json_decode($jsondata, true);


$result = array_values(json_decode($jsondata, true));

//access it as an object:


how to convert an array into JSON with PHP?

 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
   echo json_encode($data_array);

JSON Handling with PHP by Parsing File Data

Json File

			"Year": "2021",
				"Winner": "Sachin",
				"Score": "4-2",
				"Runner-up": "Khijadiya"
			"Year": "2019",
				"Winner": "Kajal",
				"Score": "1-0",
				"Runner-up": "NagarPipaliya"
			"Year": "2015",
				"Winner": "Sandeep",
				"Score": "1-0",
				"Runner-up": "Rajkot"

use of the power of PHP built-in functions : RecursiveIteratorIterator

 $val) {
    if(!is_array($val)) {
        if($key == "Year") {
            print "
"; } print $key." : ".$val . "
"; } } ?>

I hope you get an idea about json_decode multidimensional array php.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype