Home >Backend Development >PHP Tutorial >为什么这段代码不能输出

为什么这段代码不能输出

WBOY
WBOYOriginal
2016-06-06 20:15:231010browse

<code><?php $db = @new mysqli('','','','',3306);
$db->query('SET NAMES utf8');
$m=$db->query('SELECT MAX(id) FROM lab')->fetch_all());
echo $m[0];
?>
</code>

var_dump输出的内容如下:

<code>array(1) { [0]=> array(1) { [0]=> string(1) "1" } } </code>

回复内容:

<code><?php $db = @new mysqli('','','','',3306);
$db->query('SET NAMES utf8');
$m=$db->query('SELECT MAX(id) FROM lab')->fetch_all());
echo $m[0];
?>
</code>

var_dump输出的内容如下:

<code>array(1) { [0]=> array(1) { [0]=> string(1) "1" } } </code>

数组用echo打印出来会报错

数组只能打印,不能echo

print_r();

那是二维数组

把echo $m[0] 改成print_r($m[0]);

理解错误信息,找出错误

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