Re: [PHP] Re: what's the difference in the following code?
- From: robert@xxxxxxxxxxxxx (Robert Cummings)
- Date: Sun, 19 Oct 2008 23:12:32 -0400
On Sun, 2008-10-19 at 23:02 -0400, Andrew Ballard wrote:
On Sat, Oct 18, 2008 at 2:34 PM, Robert Cummings <robert@xxxxxxxxxxxxx> 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.
Yes, I didn't realize Yeti had changed the OP's code which convoluted
the issue since his version wasn't what I was responding to and I didn't
realize he dropped a line from the OP's code.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
.
- Follow-Ups:
- Re: [PHP] Re: what's the difference in the following code?
- From: "Andrew Ballard"
- Re: [PHP] Re: what's the difference in the following code?
- References:
- what's the difference in the following code?
- From: Lamp Lists
- Re: what's the difference in the following code?
- From: Carlos Medina
- Re: [PHP] Re: what's the difference in the following code?
- From: Yeti
- Re: [PHP] Re: what's the difference in the following code?
- From: Robert Cummings
- Re: [PHP] Re: what's the difference in the following code?
- From: "Andrew Ballard"
- what's the difference in the following code?
- Prev by Date: Re: [PHP] Re: what's the difference in the following code?
- Next by Date: Re: [PHP] Re: what's the difference in the following code?
- Previous by thread: Re: [PHP] Re: what's the difference in the following code?
- Next by thread: Re: [PHP] Re: what's the difference in the following code?
- Index(es):