Starting PHP |
|
2024-11-23 |
|
|
9 |
|
|
Numbers (integers and real)
<?php
$a = 1234;
$b = 0777;
$c = 0xff;
$d = 1.25;
$e = 10e5;
echo "$a $b $c $d $e<br />\n";
?>
Output
1234 511 255 1.25 1000000
Strings
<?php
$a = 'can'; $b = 'forms';
$str1 = 'Let\'s use literals.'; // Single-quoted
$str2 = "\nEmbeded vars {$a} come in many $b.\n"; // Double-quoted
$str3 = <<<HEREDOC
we even support Perl like syntax.
HEREDOC;
echo $str1.nl2br($str2).nl2br($str3);
?>
Output
Let's use literals.
Embeded vars can come in many forms.
we even support Perl like syntax.
Booleans
<?php
$greeting = True;
if ($greeting) {
echo "Hi There!";
$greeting = FALSE;
}
?>
Output
Dynamic Typing
- • Don't have to declare types
- • Automatic conversion done
<?php
echo 5 + "1.5" + "10e2";
?>
Output