Home  >  Article  >  Backend Development  >  What should I do if php cannot directly output an array?

What should I do if php cannot directly output an array?

藏色散人
藏色散人Original
2021-06-26 09:18:162065browse

php cannot output arrays directly because echo is used to output strings, not arrays. You can use "print_r($id)" to output an array or use "var_dump($id)" to view the array. Can.

What should I do if php cannot directly output an array?

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

What should I do if php cannot directly output an array?

Specific question:

php array problem, why can’t the array be output?

$id = array();
$q = $db->query("select * from wp_files where userid='$userid' and is_del=1");
while ($rs = $db->fetch_array($q)) {
$id[] = $rs[file_id];
echo $rs[file_id];
echo $id;
}

Output $rs[uid] Normally $uid is Array

Output $rs[file_id] Normally $id is Array

Solution:

The array type created by $id

And echo is used to output strings

You can use print_r($id) to output an array

or use the commonly used var_dump($id) to see values ​​and data types.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What should I do if php cannot directly output an array?. 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