RE: [PHP] have some free time?

From: Date: Wed, 02 Jul 2003 11:03:15 +0000
Subject: RE: [PHP] have some free time?
Groups: php.general 
Request: Send a blank email to php-general+get-153690@lists.php.net to get a copy of this message
> -----Original Message----- > From: Kyle Babich [mailto:php@kyle.sent.com] > Sent: 02 July 2003 00:19 > > I think this is short example of my problem... > > <?php > > $name = 'kyle'; > > function hello() { > print 'hello ' . $name; > $x = 1; > } > > function bye() { > if ($x == 1) print 'x = 1'; > else print 'x != 1'; > } > > hello(); > bye(); > > ?> > > Right now this returns: hello x != 1 > What do I have to do to get bye() to return 'x = 1'? I tried declaring > the x = 1 in hello() global and I tried declaring it static. Possibilities: function hello($x) { print 'hello ' . $name; $x = 1; } function bye($x) { if ($x == 1) print 'x = 1'; else print 'x != 1'; } hello($y); bye($y); -------------- function hello() { print 'hello ' . $name; $x = 1; return $x; } function bye($x) { if ($x == 1) print 'x = 1'; else print 'x != 1'; } $y = hello(); bye($y); -------------- function hello() { global $x; print 'hello ' . $name; $x = 1; } function bye() { global $x; if ($x == 1) print 'x = 1'; else print 'x != 1'; } hello(); bye(); Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: m.ford@lmu.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#153690) next »