note 76734 rejected from function.echo by tularis

From: Date: Fri, 19 Oct 2007 06:59:37 +0000
Subject: note 76734 rejected from function.echo by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-131534@lists.php.net to get a copy of this message
Note Submitter: scott at truebluewc dot com ---- <? 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.

« previous php.notes (#131534) next »