I am currently using the below code to echo a few different variables and 2 line breaks.
But what I would like to know is how can I echo all of the variables including line breaks into one line of code?
<?php
function findworld($var) {
return strpos($var, "world");
}
$firstvar = "hello world";
$secondvar = findworld($firstvar);
$thirdvar = strlen($firstvar);
echo $firstvar;
echo "<br />";
echo $secondvar;
echo "<br />";
echo $thirdvar;
?>
the concat operator in php is "."
echo $firstvar . "<br />" . $secondvar . "<br />" . $thirdvar;
You can use string concatenation:
echo $firstvar . "<br />" . $secondvar . "<br />" . $thirdvar;
You can pass multiple parameters to echo
, separated by a comma:
echo $firstvar, "<br />", $secondvar, "<br />", $thirdvar;
To avoid repeating the line break, you could also use implode
:
$firstvar = "hello world";
$values = array($firstvar,
findworld($firstvar),
strlen($firstvar));
echo implode('<br />', $values);
Like others have said, but with speech marks in the all the correct places ;)
echo $firstvar.'<br />'.$secondvar.'<br />'.$thirdvar;
You don't need to concatenate at all with double quotes, you can just:
echo "$firstvar<br />$secondvar<br />$thirdvar";