<?php
$x = 1;
$y = 2;
$sum = $x + $y;
echo $sum;
?>
to the HTML document when executed by a browser.
C Style:
/* This is a
multiline comment. */
Unix Style: # This is a comment
Datatype | Description or Examples |
---|---|
boolean |
TRUE or FALSE
Internally, TRUE is represented as 1, FALSE is represented as the empty string. |
integer | 3542, 0, -143, ... |
float | 3.14159, 2.7128, -45.0, 3.283e17, ... |
string | "hello", 'abc', " " (space), "" (empty string), ... |
array | Holds a list of items. |
object | Holds an object instance created from a class. |
resource | Holds an resource such as a file, image or database. |
null |
Represents an uninitialized variable. Its only possible value is NULL. |
$s = <<<END <html> <body> <p>Hello</p> </body> </html> END;
\n New Line \r Carriage Return \t Horizontal Tab \\ Backslash \$ Dollar Sign \" Double Quote
<?php
$numb_items = 45;
$output = "The number of items is $numb_items."
echo $output;
?>
The number of items is 45.
<?php
$text = "news";
$output = "Where's the $textpaper?";
?>
<?php
$text = "paper";
$output = "Where's the {$text}paper?";
echo $output;
?>
Where's the newspaper?
<?php
$raccoons = 7;
$animalname = "raccoons";
echo "The number of $animalname is ", $$animalname, ".";
?>
The number is raccoons is 7.
<?php
$raccoons = 7;
$animalname = "raccoons";
echo "The number of $animalname is ${$animalname}.";
?>
The number of raccoons is 7.
= =+ =- =* =/ =% =.
== === != <> !==
< <= > >=
and or xor ! && ||
string to int or float Convert as much of the beginning of the string that can be convertied to a number. If there is no initial numeric part, convert to zero.
boolean to int FALSE is converted to 0, TRUE is converted to 1.
boolean to string FALSE is converted to "", TRUE is converted to "1".
array to int Convert to 0 if the array contains zero items, 1 otherwise.
array to string Always convert to the string "Array".
anything to array Convert to array of one item.
If the body of a control structure has only one line, braces are not necessary.