Getting Started With Variables

text zoom

Getting Started With Variables


1. PHP Syntax


The PHP script strat with less than and question mark signs (<?) and end with question mark and greater than sign (?>) any code will be written between these tags.


<?


echo "My First Page of PHP";


echo "I am learning PHP";


?>



2. What is a Variable?


A variable is a container that stores the information that you want to use on the page for later use. You can save text and numbers in variable. As the name shows it’s a variable so you can change values (text or number) in variable.


Any text with $ sign will become variable in php


<?


$myNum=1;


$myText="This is my first variable text.";


?>


 


 Variables are case sensitive.


   



3. Joining direct text and variable data


 


   $myText="This is my first variable test.";


   $myJoinText=$myText." This is the joing text with variable.";


   $myJoinText2="This is Text1."." This is Text2.";  


   echo $myJoinText;


   echo $myJoinText2;


 


   Note


     The "." dot sign used to concat the two variables or strings.



4. Adding up in PHP


To add one number to another, the + symbol is used in PHP. If you see 4 + 3, it means add 3 into 4.


<?   


echo 2+2;


$a=4;


$b=3;


echo $a+$b;


$add=$a+$b;


echo "The added values are = ".$add;


?>


  
5. Subtraction


To subtract one number from another, the - symbol is used in PHP. If you see 4 - 3, it means subtract 3 from 4.


<?   


echo 2-2;


$a=4;


$b=3;


echo $a-$b;


$subtract=$a-$b;


echo "The subtracted values are = ".$subtract;


?>


6. Multiplication


To multiply two numbers, the * symbol is used in PHP. If you see 4 * 3, it means multiply 3 with 4.


<?   


echo 2*2;


$a=4;


$b=3;


echo $a*$b;


$multiply=$a*$b;


echo "The multiplicated values are = ".$multiply;


?>


7. Division


To divide two numbers, the / symbol is used in PHP. If you see 4 / 2, it means divide 4 by 2.


<?   


echo 2/2;


$a=4;


$b=2;


echo $a/$b;


$divide=$a/$b;


echo "The divided values are = ".$divide;


?>




 


                    

Copyright © 2008 VisualBuilder. All rights reserved