PHP 101 (part 5) - The Wonderland Factor - Q
(Page 5 of 7 )
How about an example?
<html>
<head>
<basefont face=Arial>
</head>
<body>
<?php
function answer_yes()
{
echo "Yes!";
}
function answer_no()
{
echo "No!";
}
?>
Would you watch an Al Pacino movie without thinking twice?
<br>
<? answer_yes(); ?>
<p>
Does 2 + 2 equal 6?
<br>
<? answer_no(); ?>
<p>
Is this the coolest PHP tutorial on the planet?
<br>
<? answer_yes(); ?>
</body>
</html>
And here's the output:
Would you watch an Al Pacino movie without thinking twice?
Yes!
Does 2 + 2 equal 6?
No!
Is this the coolest PHP tutorial on the planet?
Yes!
You can also invoke a function before it's been defined.
<html>
<head>
<basefont face=Arial>
</head>
<body>
Would you watch an Al Pacino movie without thinking twice?
<br>
<? answer_yes(); ?>
<p>
Does 2 + 2 equal 6?
<br>
<? answer_no(); ?>
<p>
Is this the coolest PHP tutorial on the planet?
<br>
<? answer_yes(); ?>
<?php
function answer_yes()
{
echo "Yes!";
}
function answer_no()
{
echo "No!";
}
?>
</body>
</html>
Next: Arguments And Responses >>
More PHP Articles
More By Vikram Vaswani and Harish Kamath, (c) Melonfire