【PHP】echo 输出数组报Array to string conversion解决办法

代码:


echo "Hello World!";

$demoName = array("kexuexiong","xiong");

echo "
";

var_dump($demoName);

echo $demoName; 

print_r($demoName);

echo "
"
; ?>

输出结果:
【PHP】echo 输出数组报Array to string conversion解决办法_第1张图片

报警告:
Warning: Array to string conversion in F:\tempProject\demo\index.php on line 11,原因是echo输出不了数组变量。解决办法是:
1、去掉该输出;
2、循环取出数组的值进行输出



echo "Hello World!";

$demoName = array("kexuexiong","xiong");

echo "
";

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 "
"
; ?>

输出结果:
【PHP】echo 输出数组报Array to string conversion解决办法_第2张图片

你可能感兴趣的:(PHP,php,开发语言)