It is used to convert the PHP objects into the JSON objects. It returns the result of the encoding operation. In the above syntax, the data must be passed as an object or as an array. Let’s see how it can be performed in Core PHP: name = "Happy" Suppose we have an object of a student having the name, age, and college, etc and we want to encode the data using json_encode(). First, we created an object $Student and initialized its parameters like name, age, and college.Then we encoded the object using json_encode() function and passed an object $Student as a parameter.įurthermore, suppose we have an array of animals and we want to encode the data using json_encode().First, we initialized an array of $animals.Then we encoded an array using json_encode() function and passed an array $animals as parameter. The problem is that at the other end Im unable to decode this using jsondecode (), the result it NULL.It is the reverse process of json_encode(). It converts the JSON object into a PHP object so that we can perform further operations on that data. In the above syntax, the data can be passed as an object or as an array, and bool is a boolean value passed as a parameter. Note: When the boolean value is true, the json_decode gives the decoded data as an array. Suppose we have an JSON object of an animals and we want to decode the data using json_decode().
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |