PHP Variables
TOC <ul><li>Declaring variables </li></ul><ul><li>Variable scope </li></ul><ul><li>Static Variable </li></ul><ul><li>Reser...
What is a variable <ul><li>Stores value </li></ul><ul><li>myName is “Joe” is $myName = “Joe”;  //strings </li></ul><ul><li...
Rules of  PHP Variable naming <ul><li>starts with a letter (A-Z, a-z) or underscore (_), followed by any number of letters...
Variable Scopes <ul><li>Local Scope </li></ul><ul><li>function myFunction () { </li></ul><ul><li>$FirstName = “Joe”; // lo...
Static Variables <ul><li>function test_count()  </li></ul><ul><li>{  </li></ul><ul><li>static $x=1;  </li></ul><ul><li>ech...
Reserved Words <ul><li>Cannot be used as constants, class names, function or method names. </li></ul><ul><li>May be used a...
Further Reading <ul><li>W3resource  PHP Variables  Tutorial </li></ul><ul><li>PHP :  Variables  -  Manual </li></ul>
Upcoming SlideShare
Loading in …5
×

Php variables

408 views

Published on

This presentation shows fundamentals of PHP
Variables - declaring variables, Variable scope
Static Variable and Reserved words.

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
408
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Php variables

  1. 1. PHP Variables
  2. 2. TOC <ul><li>Declaring variables </li></ul><ul><li>Variable scope </li></ul><ul><li>Static Variable </li></ul><ul><li>Reserved words </li></ul>
  3. 3. What is a variable <ul><li>Stores value </li></ul><ul><li>myName is “Joe” is $myName = “Joe”; //strings </li></ul><ul><li>UserId is 086AFTG is $UserId = 086AFTG; // numbers </li></ul>
  4. 4. Rules of PHP Variable naming <ul><li>starts with a letter (A-Z, a-z) or underscore (_), followed by any number of letters, numbers, or underscores. </li></ul><ul><li>variable name is case-sensitive. So $MyName and $MYNAME are not same. </li></ul><ul><li>You don’t need to mention what kind of value you are going to store. </li></ul>
  5. 5. Variable Scopes <ul><li>Local Scope </li></ul><ul><li>function myFunction () { </li></ul><ul><li>$FirstName = “Joe”; // local </li></ul><ul><li>//do something } </li></ul><ul><li>Global Scope </li></ul><ul><li>$department = “Marketing”; // global </li></ul><ul><li>function myFunction () { </li></ul><ul><li>$FirstName = “w3resource”;  </li></ul><ul><li>//do something } </li></ul>
  6. 6. Static Variables <ul><li>function test_count() </li></ul><ul><li>{ </li></ul><ul><li>static $x=1; </li></ul><ul><li>echo $x; </li></ul><ul><li>$x++; </li></ul><ul><li>} </li></ul><ul><li>test_count(); test_count(); test_count(); </li></ul><ul><li>//Displays 123 </li></ul>
  7. 7. Reserved Words <ul><li>Cannot be used as constants, class names, function or method names. </li></ul><ul><li>May be used as variable names, but confusing so avoidable. </li></ul><ul><li>Examples: case, namespace, __METHOD__ etc. </li></ul>
  8. 8. Further Reading <ul><li>W3resource PHP Variables Tutorial </li></ul><ul><li>PHP :  Variables  -  Manual </li></ul>

×