Echo array values in Error Message
I have an array and I want to sho开发者_Go百科w the values of the array as part of an error message. But of course when I do the code below I just get my error message with array at the end. Please help
$matches = array("2","35","27");
Now I just want to show the values to in a error message.
if (isset($matches)){
$error_message = "The following numbers match: " . $matches;
}
echo $error_message;
Result:
The following numbers match: 2 35 27
The simplest way I can think of is using implode
. You may want to do an is_array
check, but this should work.
$error_message = "The following numbers match: " . implode(' ', $matches);
Try this code:
<?php
$matches = array("2","35","27");
if (isset($matches)){
$error_message = "The following numbers match: " . var_export($matches, true);
}
echo $error_message . "\n";
?>
OUTPUT
The following numbers match: array (
0 => '2',
1 => '35',
2 => '27',
)
Look at the var_export manual here.
精彩评论