Because the interface party requires that data is processed in JS, the php program needs to take out the values from the database and assign them to the js array. I have never found a good solution because the data encoding of PHP arrays is different from that of JS arrays, and I cannot output it directly.
After searching online, the solution found:
The PHP function library provides functions for encoding/decoding JSON: json_encode() and json_decode(), which can easily pass arrays or objects to javascript. Note: JSON extension is bound only by PHP 5.2 or above.
Write in php as follows:
The code copy 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 referring to the above php file in the page, you can directly operate on data in js.