为什么这个PHP code只是回声"数组"? [英] Why does this PHP code just echo "Array"?

查看:105
本文介绍了为什么这个PHP code只是回声"数组"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的code:

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; // <--
  }
}

回声$ errormessage的运行时,它输出阵列。我在做什么错了?

When echo $errormessage runs it outputs Array. What am I doing wrong?

推荐答案

您在呼唤回声一个实际的阵列,它没有再$ P $隐式串上psentation。

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 code只是回声&QUOT;数组&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆