Course Title: Web Development Masterclass
Course Link: http://youaccel.com/admin/cdisplay.ph...
Facebook: / youaccel
Twitter: / youaccel
Website: http://youaccel.com
Tutorial Content:
When programming in PHP, you will often work with functions. A function is a block of statements that can be used repeatedly in a program. Functions can be used to perform many different types of actions, and PHP has 1000's of them built-in. We will be exploring functions later in this course.
For now, it's just important to know how to work with variables inside and outside a function.
A variable that is declared outside a function is known as a global scope variable. It can only be accessed outside a function.
In this example, we have declared the variable x (with a value of 5) outside the function (test1). This means that it is a global variable.
The purpose of this function is to output the value of x.
Since x has been declared outside the function, the output will not work. It produces an error.
If we try to access the variable outside the function, using the same echo statement. We can see it now works.
In contrast to a global scope variable, we also have local scope variables.
A local scope variable can only be accessed inside a function.
In this example, we have a function named test2.
Inside this function we have declared variable y and assigned a value of 5.
If we try to output the value of y inside the function, then we can see in our browser that it does work.
If we try to access the value of y outside the function, it results in an error.
Auf dieser Seite können Sie das Online-Video PHP Variable Scope | Tutorial mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer YouAccel 09 Mai 2019 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 15 Mal angesehen und es wurde von 0 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!