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

  • Neel Bhardwaj

  • 15-Jan-2022


  • 171

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



EG : 

$some_array = [

   "name" => "anonymous"


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



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

Fatal error: Cannot declare class Connection, because the name is already in use in /home/d8ouyzxnuef4/public_html/ on line 3