Is order of variables important in php?
Order of statements is. PHP does things in the order you tell it to do them.
if php processes variables from top to bottom then ,why does “echo $url” not display the value of first variable
It does. It’s just that that variable no longer has the value you gave it on line 1 because you gave it a new value on line 3.
And in this situation how will I be able to echo the value of first variable?
There are lots of approaches to that and …
Do I need to move the first variable from top to middle?
… would do it, but makes the line $url="$url$uri";
entirely pointless.
You need to step back and think about what you actually want to achieve.
If you need to keep the URL to the site root around and have the combined URL available somewhere, then maybe introducing a third variable name is the way forward.
If you are just debugging and want to make sure the value of $url
is right before you change it, then you should probably move your echo
statement instead.
solved Is order of variables important in php?