1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP... what kind of array/variable is this?

Discussion in 'PHP & Perl' started by upl8t, Jul 5, 2012.

  1. upl8t

    upl8t Regular Member

    Joined:
    Apr 9, 2008
    Messages:
    475
    Likes Received:
    84
    Location:
    New Scotland
    Saw something in some code today that I've never seen before.
    PHP:
    $_['textname'] = 'Text String';
    Anyone know what this is and how/why it's used? It was a file used to assign a bunch of text variables for display in various places on a website.
     
  2. artizhay

    artizhay BANNED BANNED

    Joined:
    Nov 21, 2010
    Messages:
    1,867
    Likes Received:
    1,335
    Strange...
    Well functions the same way on my home server as a regular variable, so there doesn't seem to be anything obviously special about it.
     
  3. upl8t

    upl8t Regular Member

    Joined:
    Apr 9, 2008
    Messages:
    475
    Likes Received:
    84
    Location:
    New Scotland
    I just dropped it into a file and echo'd it out. It works fine. I just don't know why they're doing it this way.
     
  4. BlueZero

    BlueZero Power Member

    Joined:
    Jul 6, 2011
    Messages:
    500
    Likes Received:
    257
    Occupation:
    Webdeveloper, Project Manager
    Location:
    Byte in the Net
    Home Page:
    Its regular variable exactly like $myArray, bu the name is _.
    They just like short names. In one of my JavaScripts i have a function named _, its good if you use it often.
     
  5. upl8t

    upl8t Regular Member

    Joined:
    Apr 9, 2008
    Messages:
    475
    Likes Received:
    84
    Location:
    New Scotland
    Thanks. I though it might have been some kind of special var. Guess it's easy to type that way.
     
  6. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    Underscore (_) is a valid variable name. So $_ is valid, just like $foo.

    Since, $foo['bar'] is an array named foo with a key named bar, so $_['test'] is an array named _ with a key named test.
     
  7. preetisoft2

    preetisoft2 Newbie

    Joined:
    Aug 27, 2012
    Messages:
    13
    Likes Received:
    1
    This is a regular variable.
     
  8. SonicSam

    SonicSam Registered Member

    Joined:
    Aug 21, 2012
    Messages:
    57
    Likes Received:
    5
    Location:
    X
    Could be used for translations, for example.

    english.php

    $_['firstname'] = "First Name";

    french.php

    $_['firstname'] = "Premier Nom";

    As others mentioned, $_ is just a variable holding an array.
     
  9. xtr3m

    xtr3m Newbie

    Joined:
    Jan 7, 2011
    Messages:
    18
    Likes Received:
    6
    Occupation:
    Web developer
    Home Page:
    Code:
    echo gettype($_);
    >array