You want to convert the result array of a database query to JSON format in PHP. The following code retrieves a row from the database:
<code class="php">$row = mysql_fetch_array($result);</code>
To convert the $row array to JSON format for use with jQuery plugins, you can utilize the json_encode function:
<code class="php">echo json_encode($row);</code>
Note that json_encode is only available in PHP version 5.2.0 and above. If you are using an earlier PHP version, you may need to use a third-party library or write your own JSON encoding function.
The above is the detailed content of How to Convert PHP Database Result Arrays to JSON?. For more information, please follow other related articles on the PHP Chinese website!