note 76734 added to function.echo
| From: | scott at truebluewc dot com | Date: | Sat, 28 Jul 2007 17:58:45 +0000 |
| Subject: | note 76734 added to function.echo | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129002@lists.php.net to get a copy of this message | ||
<?
function yrsolder ($person=0)
{
$george = 29;
$bobby = 27;
if($person==0) // george
{$yrs = ($george-$bobby);}
if($person==1) // bobby
{$yrs = ($bobby-$george);}
}
echo "I am ".yrsolder(1)." years older than Bobby!";
?>
Will output:
3I am older than Bobby!
instead of
I am 3 years older than Bobby!
This is because php will call functions when they are referenced, before an echo statement is
called. So if you have an echo statement inside the function, that echo statement is called first,
then the echo statement that originally called the function.
----
Server IP: 69.147.83.197
Probable Submitter: 76.187.6.89
----
Manual Page -- http://www.php.net/manual/en/function.echo.php
Edit -- https://master.php.net/note/edit/76734
Del: integrated -- https://master.php.net/note/delete/76734/integrated
Del: useless -- https://master.php.net/note/delete/76734/useless
Del: bad code -- https://master.php.net/note/delete/76734/bad+code
Del: spam -- https://master.php.net/note/delete/76734/spam
Del: non-english -- https://master.php.net/note/delete/76734/non-english
Del: in docs -- https://master.php.net/note/delete/76734/in+docs
Del: other reasons-- https://master.php.net/note/delete/76734
Reject -- https://master.php.net/note/reject/76734
Search -- https://master.php.net/manage/user-notes.php