PHP

How to convert array into json API in PHP || how to use json encode and decode in PHP.

  • Neel Bhardwaj

  • 15-Jan-2022

  • 0 comments

  • 120

In API json is the most important. All data send in json formate.

So it's important to you to know how json work.

Here is the simple example of json :

{

  "name" : "anonymous'

}

Actually its object type. Key=Value pair.

So here is the question. How to convert array into json formate in PHP.

In PHP there is default function given which convert ARRAY=JSON

json_encode()

 

EG : 

$some_array = [

   "name" => "anonymous"

]

So convert this array into json. Simply use json_encode();

json_encode($some_array);

 

Result :

{

  "name" : "anonymous'

}

 

 

"Programming isn't about what you know,
it's about what you can figure out.”
Chris Pine

Neel Bhardwaj

A full stack developer. I have a Passion for Creating Clean, Beautiful, Interactive, Minimalistic, Responsive and User Friendly website, Developed by Modular, Scalable and Functional Code.

Recent comments

Leave a reply