The PHP function library provides functions for encoding/decoding JSON: Json_encode () and Json_decode (), which can be used to pass arrays or objects to JavaScript in a more convenient
Because the interface side of the request, with JS processing data, so need PHP program from the database after the value assigned to the JS array. has not found a good way, because the PHP array of data encoding and JS array encoding format is not the same, can not directly output. After a search on the Web, find a solution: PHP function Library provides the function of encoding/decoding JSON: Json_encode () and Json_decode (), can be more convenient to pass the array or object to JavaScript. Note: More than 5.2 of PHP is bound to the JSON extension. Write in PHP as follows: The code is as follows: $arr = Array (' 1 ', Array (' 2 ', ' 3 '), Array (' new ', ' old ')); $new _arr = Json_encode ($arr); the output result of//new_arr is; ["1", ["2", "3"],["new", "old"]] echo "var data =". $new _arr; After referencing the above PHP file in the page, the data can be operated directly in JS.