Re: Re: what's the difference in the following code?

From: Date: Mon, 20 Oct 2008 03:02:41 +0000
Subject: Re: Re: what's the difference in the following code?
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-282122@lists.php.net to get a copy of this message
On Sat, Oct 18, 2008 at 2:34 PM, Robert Cummings <robert@interjinn.com> wrote: > > On Sat, 2008-10-18 at 08:44 -0700, Yeti wrote: > > I would understand it if it was like this .. > > > > <?php > > $search = isset($_GET['search']) ? $_GET['search'] : ''; > > # versus > > if (isset($_GET['search'])) { $search = $_GET['search']; } > > ?> > > > > In the first statement $search would either be set to $_GET['search'] > > or an empty string, whereas in the second statement $search would only > > be set, if there is a $_GET['search'] > > Wrong. They are equivalent. The second is probably just easier to follow > with a clearly defined default value outside the conditional block. > > Cheers, > Rob. No, they are not. In the first statement, $search is the value of $_GET['search'] if the key exists, or an empty string if it does not. In the second statement, $search is the value of $_GET['search'] if the key exists or retains its original value if the key does not exist. Andrew

« previous php.general (#282122) next »