SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Michigan
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_GET Parameters

    Wow, I didn't ever really catch onto this until today.

    PHP Code:
    if($_GET['sortby'] == "letter"
    is the same thing as

    PHP Code:
    if($_GET['sortby']['letter']) 
    Now, is there any differences in the two? I have a script running and for some reason I changed it to the second one and to my surprise it worked.

    Maybe it just never hit me, but it works. Anyone have a say on the two?

  2. #2
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    These are not the same.
    PHP Code:
    $_GET['sortby'] == "letter" 
    would imply that $_GET['sortby'] value is a string.
    PHP Code:
    $_GET['sortby']['letter'
    means that $_GET['sortby'] value is an array. "['letter']" here would be an index in any array in $_GET['sortby'].

    In the first example your comparing a string "letter" to the contents of $_GET['sortby'] where as in the second example your checking the value in $_GET['sortby']['letter'] for something that evaluates as a boolean true.
    Erh

  3. #3
    SitePoint Wizard
    Join Date
    Oct 2001
    Location
    Tucson, Arizona
    Posts
    1,858
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by PlayOn
    Now, is there any differences in the two?
    Yes! They're not the same!

    Edit: Mandibal beat me to it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •