Variables
-
Upload
suraj-motee -
Category
Internet
-
view
129 -
download
0
Transcript of Variables
![Page 1: Variables](https://reader035.fdocuments.net/reader035/viewer/2022071903/55c4a05dbb61eb52458b4633/html5/thumbnails/1.jpg)
VARIABLESIN PHP
Presenter: Suraj Motee
![Page 2: Variables](https://reader035.fdocuments.net/reader035/viewer/2022071903/55c4a05dbb61eb52458b4633/html5/thumbnails/2.jpg)
WHAT ARE VARIABLES?
Variables are "containers" for storing information.
In PHP, a variable starts with the $ sign, followed by the name of the variable.
![Page 3: Variables](https://reader035.fdocuments.net/reader035/viewer/2022071903/55c4a05dbb61eb52458b4633/html5/thumbnails/3.jpg)
QUESTION:
$x=3;$y=4;$x=$y;
What is the final value of $x?How to output the value of $x?
![Page 4: Variables](https://reader035.fdocuments.net/reader035/viewer/2022071903/55c4a05dbb61eb52458b4633/html5/thumbnails/4.jpg)
RULES FOR PHP VARIABLES
A variable starts with the $ sign, followed by the name of the variable
A variable name must start with a letter or the underscore character
A variable name cannot start with a numberA variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
Variable names are case-sensitive ($age and $AGE are two different variables)
![Page 5: Variables](https://reader035.fdocuments.net/reader035/viewer/2022071903/55c4a05dbb61eb52458b4633/html5/thumbnails/5.jpg)
GLOBAL VARIABLES
![Page 6: Variables](https://reader035.fdocuments.net/reader035/viewer/2022071903/55c4a05dbb61eb52458b4633/html5/thumbnails/6.jpg)
LOCAL VARIABLES
![Page 7: Variables](https://reader035.fdocuments.net/reader035/viewer/2022071903/55c4a05dbb61eb52458b4633/html5/thumbnails/7.jpg)
QUESTION:
How to output the value of $x inside the function which has a global scope?
![Page 8: Variables](https://reader035.fdocuments.net/reader035/viewer/2022071903/55c4a05dbb61eb52458b4633/html5/thumbnails/8.jpg)
THE STATIC KEYWORD
Normally, when a function is completed/executed, all of its variables are deleted. However, sometimes we want a local variable NOT to be deleted. We need it for a further job.
To do this, use the static keyword when you first declare the variable
![Page 9: Variables](https://reader035.fdocuments.net/reader035/viewer/2022071903/55c4a05dbb61eb52458b4633/html5/thumbnails/9.jpg)
QUESTIONS?
DOES STATIC MEANS LOCAL & GLOBAL?
Verify the concept using local/global concepts.
![Page 10: Variables](https://reader035.fdocuments.net/reader035/viewer/2022071903/55c4a05dbb61eb52458b4633/html5/thumbnails/10.jpg)
$GLOBALS[INDEX]
PHP also stores all global variables in an array called $GLOBALS[index]. The index holds the name of the variable. This array is also accessible from within functions and can be used to update global variables directly.