Jump to content

Wrong Order of Output


TerraBuilder

Recommended Posts

I wrote a statement to display a number and write a string true or false after testing it to be a double. Although, if I write it in the first echo statement, it goes out of order. This wont happen if I separate into another echo statement on the next line.

 

<?
function check($num){ //function to change
if(is_double($num)){
echo "TRUE";
}else{
echo "FALSE";
}
}
$number=3.1415;
echo "Is ".$number." a double?".check($number); //Output
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/186387-wrong-order-of-output/
Share on other sites

echo true or false in the function will run before the echo of your main statement will, you should use return, your  should have been, I just shorten the code a bit.

 

<?php
function check($num){ //function to change
return is_double($num) ? "TRUE" : "FALSE";
}
$number=3.1415;
echo "Is ".$number." a double?".check($number); //Output
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.