Sunday, September 7, 2008
Some PHP Exercises
What is the difference between using single quotes and double quotes in the echo function?
Friday, September 5, 2008
The echo function
Syntax: echo variable-name;
echo “smith”;
2.
$name = “Jones”;
echo $name;
3.
$name=”Natasha”;
echo “My name is $name”;
echo “
”
echo “What is yours?”;
4.
$name = “Robin”;
echo ‘My name is $name’
5.
echo ‘My’,’name’,’is’,’John’;
Smith
2.
Jones
3.
My name is Natasha
What is yours?
4.
My name is $name
5.
My name is John
Some PHP Exercises
What are the rules for naming a PHP variable?
Can I start a PHP variable name with the # symbol?
Should we always declare a variable in PHP specifying its data type?
Is it true that all statements in PHP should end with a comma?
Thursday, September 4, 2008
Variables in PHP
Variables are identifiers to the memory location to store data. A PHP program can contain as many variables as you’d want.
Variable names in PHP begin with a dollar sign "$" and the values are assigned using the “=” operator.
Following the $ sign should be an alphabet or an underscore.
A variable name can contain any number of alphabets, numbers or underscores.
A PHP variable name cannot contain special characters like *, +, @, # etc.
In PHP we need not specify the variable type, as PHP takes the data type of the assigned value.
1. $1name is an invalid variable name as it starts with a number.
2. $_name or $name1 are, however, valid PHP variable names.
3.
$Name = "David";
$Age = 16;
In the above case, we assign values to the variable without mentioning their type. PHP automatically recognizes $Age as a numeric variable and $Name as a string.