PHP: Variables, Constants and Scope: Favorite Colors
Let's create a variable called $favColorToday and assign it the string "purple". Then we will echo it.
My favorite color today is: purple
Let's create a second variable called $favColorTomorrow and assign it the string "red".
Perhaps my favorite color tomorrow will be: red
Now we'll assign $favColorToday to $favColorTomorrow by reference.
On the other hand, perhaps my favorite color tomorrow will still be: purple
Now let's play with scope and see what a second $favColorToday defined inside the function favColor() is...
My favorite color today inside favColor() is: green
Yet outside of favColor(), $favColorToday is still: purple
Now change $favColorTomorrow to green.
My favorite color today, outside of favColor(), is now: green
Now change $favColorToday back to purple.
My favorite color tomorrow is now also: purple
Let's create a new variable $secondFavColorToday to store my second favorite color today, grey. We will pass it by reference to a function, where we will change it to blue.
My second favorite color today inside secondFavColor() is: blue
My second favorite color today, outside of secondFavColor(), is now: blue
SYS_COLOR was defined, and this constant is: orange in the main document.
Calling favSysColor(), and SYS_COLOR is still: orange in this function as it's scope is throughout the main document and all functions.