Solution to garbled php output array: 1. Open the corresponding php file; 2. Check whether the encoding is set; 3. Add "header("Content-type:text/html;charset= at the beginning of the file utf-8 ");" statement is enough.
The operating environment of this tutorial: Windows 10 system, PHP version 8.1, DELL G3 computer
#What should I do if the output array of php is garbled?
Solution to Chinese garbled characters:
header("Content-type:text/html;charset=utf-8");
For example:
Use print_r() to output an array
The print_r() function is used to Print variables in a more understandable form. The print_r() function can output the contents and structure of the entire array, and the keys and elements will be displayed in a certain format.
"张三","年龄"=>25,"性别"=>"男"), array("姓名"=>"李四","年龄"=>21,"性别"=>"男"), array("姓名"=>"娜娜","年龄"=>22,"性别"=>"女") ); print_r($array); ?>
Output:
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What to do if php output array is garbled. For more information, please follow other related articles on the PHP Chinese website!