我不断收到通知,“注意:第33行路径名中的数组到字符串转换”。当我隐藏通知error_reporting(E_ALL ^ E_NOTICE);
时,我仍然会出现“数组”这个词出现的次数与我返回的行数一样多。作为新人我似乎无法摆脱他们。代码中的错误就在这附近。
<?php
$query = 'SELECT * FROM NETWORK';
$result = mysqli_query($conn,$query);
while($r=mysqli_fetch_assoc($result)){
echo $rows["network"][] = $r;
}
print json_encode($rows);
?>
当我在浏览器上测试时,它会返回此信息。
Notice: Array to string conversion in /var/www/html/dl.php on line 33
Array
Notice: Array to string conversion in /var/www/html/dl.php on line 33
Array
Notice: Array to string conversion in /var/www/html/dl.php on line 33
Array
Notice: Array to string conversion in /var/www/html/dl.php on line 33
Array
Notice: Array to string conversion in /var/www/html/dl.php on line 33
Array
Notice: Array to string conversion in /var/www/html/dl.php on line 33
Array
Notice: Array to string conversion in /var/www/html/dl.php on line 33
Array
Notice: Array to string conversion in /var/www/html/dl.php on line 33
Array
Notice: Array to string conversion in /var/www/html/dl.php on line 33
Array
Notice: Array to string conversion in /var/www/html/dl.php on line 33
Array
{"network":[{"lid":"1","sid":"1","player_id":"1","active":"1"},
{"lid":"1","sid":"1","pid":"4","active":"1"},
{"lid":"1","sid":"2","pid":"2","active":"1"},
{"lid":"1","sid":"2","pid":"5","active":"1"},
{"lid":"1","sid":"3","pid":"3","active":"1"},
{"lid":"2","sid":"1","pid":"1","active":"1"},
{"lid":"2","sid":"2","pid":"2","active":"1"},
{"lid":"2","sid":"2","pid":"4","active":"1"},
{"lid":"2","sid":"3","pid":"3","active":"1"},
{"lid":"2","sid":"3","pid":"5","active":"1"}]}
总体问题是我做错了什么?但是因为我得到通知而不是错误,我认为可能没有错,但也许有更好的方法来获得我想要的最终结果,这是用json编码的数组。所有和任何帮助表示赞赏。
答案 0 :(得分:1)
摆脱echo
。 $r
是一个不是字符串的数组,不能与echo
一起使用:
//echo $rows["network"][] = $r;
$rows["network"][] = $r;
为什么要构建$rows
但json_encode
$rows3
?