为什么这段 PHP 代码只回显“数组"? [英] Why does this PHP code just echo "Array"?
本文介绍了为什么这段 PHP 代码只回显“数组"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
if(isset($_POST['check']) AND $_POST['check'] == 'First') {
$errormessage = array();
if(empty($_POST['full_name']) || strlen($_POST['full_name']) < 4) {
$errormessage[] = "FEL - Vänligen ange fullständiga namn. Please enter atleast 3 or more characters for your name";
}
if(!isEmail($_POST['usr_email'])) {
$errormessage[] = "FEL - Invalid email address.";
}
if(empty($errormessage)) {
echo 1;
} else {
echo $errormessage; // <--
}
}
当echo $errormessage
运行时,它输出Array
.我做错了什么?
When echo $errormessage
runs it outputs Array
. What am I doing wrong?
推荐答案
您正在对实际数组调用 echo
,该数组没有隐式字符串表示.
You are calling echo
on an actual array, which does not have an implicit string representation.
为了输出数组的内容,您可以使用 print_r
、var_dump
或 var_export
函数或自定义输出,您可以使用 array_map
甚至是 foreach
循环:
In order to output an array's contents you can use the print_r
, var_dump
or var_export
functions or for custom output, you can use array_map
or even a foreach
loop:
print_r($errormessage);
var_dump($errormessage);
var_export($errormessage);
foreach($errormessage as $error)
echo $error . '<br/>';
array_map('echo', $errormessage);
这篇关于为什么这段 PHP 代码只回显“数组"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文