Home  >  Article  >  Backend Development  >  How to Convert a MySQL Result Array to JSON in PHP?

How to Convert a MySQL Result Array to JSON in PHP?

Susan Sarandon
Susan SarandonOriginal
2024-11-02 09:51:31197browse

How to Convert a MySQL Result Array to JSON in PHP?

Converting MySQL Result Array to JSON

In PHP, you can easily convert a MySQL result array to JSON format using json_encode(). This function is available in PHP versions 5.2.0 and later.

To convert a PHP result array, $row, to JSON, simply use the following code:

<code class="php">echo json_encode($row);</code>

The generated JSON data can then be passed to your jQuery plugin as needed.

The above is the detailed content of How to Convert a MySQL Result Array to JSON in PHP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn