代码:
<?PHP
echo "Hello World!";$demoName = array("kexuexiong","xiong");echo "<pre>";var_dump($demoName);echo $demoName; print_r($demoName);echo "</pre>";
?>
输出结果:
报警告:
Warning: Array to string conversion in F:\tempProject\demo\index.php on line 11
,原因是echo输出不了数组变量。解决办法是:
1、去掉该输出;
2、循环取出数组的值进行输出
<?PHPecho "Hello World!";$demoName = array("kexuexiong","xiong");echo "<pre>";var_dump($demoName);
echo PHP_EOL;
for ($i=0; $i < count($demoName); $i++) {
echo $demoName[$i].PHP_EOL;
}echo PHP_EOL;print_r($demoName);echo "</pre>";
?>
输出结果:
发表评论 取消回复