Quick Table of Contents
[Edit] Creating Variables
Creating a variable in PHP is known as declaring it. Declaring a variable is as simple as using its name in
your script: $my_first_variable;When PHP first sees a variable ’ s name in a script, it automatically creates the variable at that point. When you declare a variable in PHP, it ’ s good practice to assign a value to it at the same time. This is known as initializing a variable. By doing this, anyone reading your code knows exactly what value the variable holds at the time it ’ s created. (If you don ’ t initialize a variable in PHP, it ’ s given the default value of null .) Here ’ s an example of declaring and initializing a variable: $my_first_variable = 3;This creates the variable called $my_first_variable , and uses the = operator to assign it a value of 3. (You look at = and other operators later) Looking back at the addition example earlier, the following script creates two variables, initializes them with the values 5 and 6 , then outputs their sum ( 11 ): $x = 5; $y = 6; echo $x + $y;
September 15, 2011
|
This Page is Under Construction! - If You Want To Help Please Send your CV - Advanced Web Core (BETA)
© Advanced Web Core. All rights reserved