• My PHP Pages

    This is a complete and free PHP programming course for beginners. Everything you need to get started is set out in section one below.

Jun 14, 2013

Posted by Unknown
1 comment | 8:45 PM



Variables are use for storing values, like string numbers or arrays. when a variable declared, it can be used over and over again in your script.

Note : All Variables in PHP start with a $ sign symbol

example : $my_variable = 100;

-----------------------------------------------------------------------------------------------------------

PHP is loosely typed language 


In PHP, a variable dose not need to be declared before adding a value to it.

<?php
$mytxt = "My PHP Page";
$x = 100;
?>


in the example above, you see that you do not have to tell PHP which data type the variable is, PHP automatically converts the variable to the correct data type , depending on its assigned value.


Naming Rules for variables 


A variable name must start with a letter or an underscore "_" (ex : $_myval or $myval)

A variable name can only contain alpha-numeric characters and underscores ( a-z , A-Z , 0-9 and _ )

A variable name should not contain spaces.


String Variables in PHP

When you store string data in variable , you should use " " marks. ( ex : $mystring = "your name" )


The concatenation operator


The concatenation operator (.) is used to put two string values together.

<?php
$txt1="My Name is : ";
$txt2="Rajika";
echo $txt1.$txt2;
?>

Output : My Name is : Rajika




1 comment :