SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to Call Value of PHP Variable on top if it's value isdeclared in bottom of page ?

    I have declared a PHP variable in bottom of the page.
    PHP Code:
    $value 10
    And want to get its value on the top of the PHP page.
    PHP Code:
    $value 
    This is urgent requirement for me.
    I love to help and also to get helped.

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is there a VALID reason you cannot set its value at the top?

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, that's why I need this workaround for only one variable.
    I love to help and also to get helped.

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    need to see your code

  5. #5
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The code is of a number of lines. I have provided a simple idea, that I need to get the value of a variable on top of the page, which is declared and defined in bottom of that page.
    There must be some way of using reference variables or something else, but i am learning PHP, and till yet i don't know that method.
    I love to help and also to get helped.

  6. #6
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Generally speaking, you cannot use a variable BEFORE you create it. I suspect you might need to rethink your logic (no offense).

    Consider

    1 top of page
    2 do something here
    3 do some more
    4 use a variable here that has no value
    5 do even more
    6 and more
    7 set a value to the variable
    8 do some 'magic' (perhaps goto IF you have the right version of php)
    you would end up all your repeating steps

    Could you explain why you cannot set the variable value earlier?

  7. #7
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks your answer worked now.
    I thought the logic again, and then declared the value on the top itself.
    I love to help and also to get helped.


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
  •