I have declared a PHP variable in bottom of the page.
$value = 10;
And want to get its value on the top of the PHP page.
$value
This is urgent requirement for me.
I have declared a PHP variable in bottom of the page.
$value = 10;
And want to get its value on the top of the PHP page.
$value
This is urgent requirement for me.
is there a VALID reason you cannot set its value at the top?
Yes, that’s why I need this workaround for only one variable.
need to see your code
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.
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?
Thanks your answer worked now.
I thought the logic again, and then declared the value on the top itself.