confused in simple variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shreedhan
    New Member
    • Jul 2007
    • 52

    #1

    confused in simple variables

    Hi

    I am trying following code

    [code=php]
    $var=2;
    print ( $_POST [' "$var" ' ] );

    [/code]

    how will the variable in print function be interpreted?
    is that equivalent to $_POST['2'] ??
    if not, is there some way to make it work similarly?

    Thanks
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    $_POST is an array. It contains data that has been posted from a HTML form. Check out this article to see how that works.

    What you wrote as an index in the $_POST array will be interpreted like so: "$var". Anything inside single quotes will be read exactly like it is written. No variables will be evaluated.

    You could write it like so:
    [code=php]
    echo $_POST[$var];
    [/code]

    And it will fetch the index marked as "2".

    Comment

    • shreedhan
      New Member
      • Jul 2007
      • 52

      #3
      Hi Atli
      Thanks for your help.
      It was the thing that I needed.
      I am gettig the names of variables from somewhere else
      So, I am using $var.

      Thanks

      Comment

      Working...