json_encode to convert data to string

Json is a data exchange format like XML. You can learn about Json support of PHP here. We will learn about php function json_encode() here. This function is built in higher versions of PHP. To know about support of your PHP version regarding Json you can check the Json Introduction page.

json_encode function takes data and converts them to a string, we call it as Json string. This string format follows a standard so it can be decoded back to its original data form at the receiving end.

Let us start with an array of data. Here is an simple data array in PHP, we will apply json_encode() to this array.

echo json_encode($a);

The output of the above code is here.


This is one of the simple requirements, so we will try some thing bit complex than this by using two arrays.

The output of the above code is here.


Note the square bracket at the outside. The two set of data are separated by a coma and included inside curl bracket.

You can start from here making your json string to exchange data across pages.
Visitors Rating
Your Rating

Post Comment This is for short comments only. Use the forum for more discussions.

HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer