When I execute this function, I get the output: "test yesThis here is a test: . That concludes the test." Rather than getting "This here is a test: test yes. That concludes the test."
How come the function's product is placed at the start of the line and not within the line as it is in the code?
<?php
$temp = "test";
$nottemp = "nottemp";
function featureAvail($x)
{
if($x == "test") {
echo "test yes";
} else {
echo "test no";
}
}
$stuff = "This here is a test: " . featureAvail($temp) . ". That concludes the test.";
echo $stuff;
?><?php
$temp = "test";
$nottemp = "nottemp";
function featureAvail($x)
{
if($x == "test") {
echo "test yes";
} else {
echo "test no";
}
}
$stuff = 'This here is a test: ' . featureAvail($temp) . '. That concludes the test.';
echo $stuff;
?>
would echo
This here is a test: test yes. That concludes the test.I changed the quotes to single quotes and it's still doing the same thing by giving me "test yesThis here is a test: . That concludes the test."
Does it have to do with how I'm appending the string?I'm thinking I might have to make $stuff an array and implode each piece...?in the function, change the echo's to returns. Something about echoing something from inside an echo. I think that it queues stuff up, and actually sends it out at the end of the echo statement. The echo in the functions finishes BEFORE the echo that it is called from. If you use return, it will simply insert the text that is returned into the echo statement that calls the function (this is what you want I think).
This works:<?php
$temp = "test";
$nottemp = "nottemp";
function featureAvail($x)
{
if($x == "test") {
return "test yes";
} else {
return "test no";
}
}
$stuff = 'This here is a test: ' . featureAvail($temp) . '. That concludes the test.';
echo $stuff;
?>That's it! Thanks Aaron!!
How come the function's product is placed at the start of the line and not within the line as it is in the code?
<?php
$temp = "test";
$nottemp = "nottemp";
function featureAvail($x)
{
if($x == "test") {
echo "test yes";
} else {
echo "test no";
}
}
$stuff = "This here is a test: " . featureAvail($temp) . ". That concludes the test.";
echo $stuff;
?><?php
$temp = "test";
$nottemp = "nottemp";
function featureAvail($x)
{
if($x == "test") {
echo "test yes";
} else {
echo "test no";
}
}
$stuff = 'This here is a test: ' . featureAvail($temp) . '. That concludes the test.';
echo $stuff;
?>
would echo
This here is a test: test yes. That concludes the test.I changed the quotes to single quotes and it's still doing the same thing by giving me "test yesThis here is a test: . That concludes the test."
Does it have to do with how I'm appending the string?I'm thinking I might have to make $stuff an array and implode each piece...?in the function, change the echo's to returns. Something about echoing something from inside an echo. I think that it queues stuff up, and actually sends it out at the end of the echo statement. The echo in the functions finishes BEFORE the echo that it is called from. If you use return, it will simply insert the text that is returned into the echo statement that calls the function (this is what you want I think).
This works:<?php
$temp = "test";
$nottemp = "nottemp";
function featureAvail($x)
{
if($x == "test") {
return "test yes";
} else {
return "test no";
}
}
$stuff = 'This here is a test: ' . featureAvail($temp) . '. That concludes the test.';
echo $stuff;
?>That's it! Thanks Aaron!!