mohansinfh — 2012-03-11T12:03:00-04:00 — #1
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.
This is urgent requirement for me.
litebearer — 2012-03-11T12:20:16-04:00 — #2
is there a VALID reason you cannot set its value at the top?
mohansinfh — 2012-03-11T12:21:17-04:00 — #3
Yes, that's why I need this workaround for only one variable.
litebearer — 2012-03-11T12:25:42-04:00 — #4
mohansinfh — 2012-03-11T12:27:58-04:00 — #5
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.
litebearer — 2012-03-11T12:38:27-04:00 — #6
Generally speaking, you cannot use a variable BEFORE you create it. I suspect you might need to rethink your logic (no offense).
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?
mohansinfh — 2012-03-11T12:45:09-04:00 — #7
Thanks your answer worked now.
I thought the logic again, and then declared the value on the top itself.