All TalkersCode Topics

Follow TalkersCode On Social Media

How To Get Data From Json Array In PHP

Last Updated : Jan 1, 2023

How To Get Data From Json Array In PHP

In this tutorial we will show you the solution of how to get data from json array in PHP and all can be done using json_decode() function. Let us understand this article with help of json decode.

As, there are many other ways with help of which we can get data from json array but in this article we are going to use the basic way or say most preferred way which is used most times.

Step By Step Guide On How To Get Data From Json Array In PHP :-

Let us understand this json decode with help of codes. One thing to show here the basic syntax of json_decode() as json_decode($jsonString, $assoc, $depth, $options);

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title> how to get data from json array in php </title>
$jsonData ='{
$output = json_decode($jsonString);
  1. First, we write <! DOCTYPE html> which we used as an instruction to the web browser about what version of HTML file is written in.
  2. Secondly, the <html> tag is used to indicate the beginning of an HTML document.
  3. As above now <head> tag is used to contain information about web page. In this tag a <title> tag is used which helps us to specify a webpage title. Both <head> and <title> tags are Paired tags. So, both have </head> and </title> ending tags respectively.
  4. Here, then we create a body tag. All the content which we want to show on browser’s screen or display is always written inside this codes.
  5. Here, inside body here we create basic structure of php. In which we use <?php and ?>.
  6. Inside these tags, we create a variable name jsonData as you can see above and inside this we assigns some values to its keys like first name and last name. You can use here as much values you want.
  7. After that we just use json_decode() and pass a parameter on which we want to apply json_decode() function. After this we store the resulted values inside a variable named output.
  8. Now, our last job is to print the required output or show the data. So, that we use var_dump which is a predefind function of php. it is used to dump information and it also tells us about the datatype used. It is mostly used to give structured value of php.
  9. Here inside var_dump() we directly pass our variable that is output. In which we store our result. We hope that you understand codes properly.
  10. At last, the <body> and <html> tags are closed with </body> and </html> respectively.

Conclusion :-

At last in conclusion, here we can say that with the help of this article we are able to understand how to get data from json array in php.

I hope this tutorial on how to get data from json array in PHP helps you and the steps and method mentioned above are easy to follow and implement

Latest Tutorials