SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    437
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    echo $row[$key] or echo $row[key];

    today, when i have read this thread
    sitepoint.com/forums/showthread.php?t=456441
    i found the
    PHP Code:
    // OK 
    echo $row[$key];  
    // Wrong, unless key is a constant 
    echo $row[key];  
    // Right 
    echo $row['key'];  
    // OK, since it's in a string 
    echo "Text: $row[key]"
    the echo $row[$key]; is wrong, echo $row[key]; is right.
    why?
    Outdoor tools online store and wargame tools shop
    with best quality and service.
    comp molle tactical vest tactical clothing etc sell

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You've got the right and wrong backwards.

  3. #3
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    437
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    ??
    according to the code, echo $row[$key]; is ok,but i have tested,it couldn't work.and who can tell me what's the difference of the rest.thank you!
    Outdoor tools online store and wargame tools shop
    with best quality and service.
    comp molle tactical vest tactical clothing etc sell

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,182
    Mentioned
    16 Post(s)
    Tagged
    4 Thread(s)
    PHP Code:
    // variable
    $row = array('key'=>'my key');

    $key 'key';
    echo 
    '<p>',$row[$key],'</p>';

    // constant
    define('key','key');
    echo 
    '<p>',$row[key],'</p>';

    // string
    echo '<p>',$row['key'],'</p>'

  5. #5
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    437
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    i got it! thanks.
    Outdoor tools online store and wargame tools shop
    with best quality and service.
    comp molle tactical vest tactical clothing etc sell


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
  •