Hi Reader's,
Welcome to FindNerd, today we are going to discuss use of json_encode() function in php.
json_encode() is used to convert the array given as it's argument into a JSON string. JSON full form is JavaScript Object Notation.
If you are using json_encode() function then always json_encode() function returns a function when json_encode() function function will work.
json_encode() function returns a JSON encoded string on success or returns FALSE on failure.
Syntax of json_encode() function
json_encode(value, options)
you can see below example:
<?php
//First you need a PHP array of data
$result = array(
'first_name' => "Tom",
'last_name' => "Gray",
'phone_number' => 123456789,
'address' => "USA"
);
//here call json_encode() function
$jsondata = json_encode($result);
//print json_encode data
print_r($jsondata);
?>
Output will come following of above example
{"first_name":"Tom","last_name":"Gray","phone_number":123456789,"address":"USA"}
0 Comment(s)