Do you know the difference between the common echo() and print() functions? Also you will find here a basic description of variable functions in PHP.
Do you know the difference between the common echo() and print() functions? Also you will find here a basic description of variable functions in PHP. <?php
php stuff
?>
Ok, now that said, let's go to what this tutorial was written for. <?php
print("This is outputted to the webpage");
print "so is this!";
?>
You can also declare variables and then output them using the print
function: <?php
$hello = "hello"
print("$hello"); //this print the hello variable
print "$hello";
?>
That's really all there is to it. One thing is that it cannot be used in
a variable function, which I'll explain in a few minutes. <?php
$kool = "this is kool";
echo ("$kool prints \"kool\"");
echo "this does too!";
echo("hello");
echo "this prints \"hello\" too!";
?>
What's the difference between the two ? Well, one difference is that
echo() can take multiple expressions: <?php
echo "The first", "the second";
?>
Print cannot take multiple expressions. That is the main distinct
difference! <?php function foo()
{
echo "In foo()\n";
}
function bar($arg = '')
{
echo "In bar(); argument was '$arg'.\n";
}
$func = 'foo';
$func();
$func = 'bar';
$func('test');
?>
In the code above there are two simple functions are declared. Then their
names are assigned to the variable and both functions are executed using this
variable.