我有一个数组,我想将数组的值显示为错误消息的一部分。但当然,当我执行下面的代码时,我只是在最后得到了带有数组的错误消息。请帮忙
$matches = array("2","35","27");
现在我只想在错误消息中显示值。
if (isset($matches)){
$error_message = "The following numbers match: " . $matches;
}
echo $error_message;
结果:
The following numbers match: 2 35 27
答案 0 :(得分:2)
我能想到的最简单的方法是使用implode
。您可能想要进行is_array
检查,但这应该有效。
$error_message = "The following numbers match: " . implode(' ', $matches);
答案 1 :(得分:0)
试试这段代码:
<?php
$matches = array("2","35","27");
if (isset($matches)){
$error_message = "The following numbers match: " . var_export($matches, true);
}
echo $error_message . "\n";
?>
<强>输出强>
The following numbers match: array (
0 => '2',
1 => '35',
2 => '27',
)