php method to convert a two-dimensional array into json data: You can use the php built-in function json_encode() to achieve this. The json_encode() function is used to json encode variables. If the execution is successful, it returns json data, otherwise it returns false.
json_encode() is used to JSON encode variables. This function returns JSON data if executed successfully, otherwise it returns FALSE.
(Recommended tutorial:php graphic tutorial)
Syntax:
string json_encode ( $value [, $options = 0 ] )
Parameters:
value: The value to be encoded . This function is only valid for UTF-8 encoded data.
options: Binary mask
(Video tutorial recommendation:php video tutorial)
Code example:
1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5); echo json_encode($arr); ?>
Execution result :
{"a":1,"b":2,"c":3,"d":4,"e":5}
The above is the detailed content of How to convert two-dimensional array to json data in php. For more information, please follow other related articles on the PHP Chinese website!