<?PHP echo "PHP Tutorial"; //PHP Tutorial echo 'PHP Tutorial'; //PHP Tutorial $a="Joni"; echo "$a PHP Tutorial"; //Joni PHP Tutorial echo '$a PHP Tutorial'; //$a PHP Tutorial ?>
Using
<?PHP //MM is self defined, as long as MM is also used to end the print out echo <<<MM This is Line 1 Line 2 MM; ?>
Special characters include double quote, single quote should be escaped using
<?PHP echo "John's daughter"; //John's daughter echo 'John's daughter'; //Error echo 'John\'s daughter'; //John's daughter echo 'John"s daughter'; //John"s daughter echo "John"s daughter"; //Error echo "John\"s daughter"; //John"s daughter ?>
Strings can be concatenated by
<?PHP $arr = array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"); foreach($arr as $dy) { echo "Today is: " . $dy . "."; } Today is: Monday. Today is: Tuesday. Today is: Wednesday. Today is: Thursday. Today is: Friday. Today is: Saturday. Today is: Sunday. ?>
Echo array element.
<?PHP $arr = array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"); for ($i=0;$i<3;$i++) { echo "$arr[$i]";//OK echo "$arr[$i + 1]";//Error $k=$i+1; echo "$arr[$k]";//OK } ?>
Echo the array element of a class object.
<?PHP class c { var $arr; public __construct() { $this->arr = array(); } } $b = new c(); $b->arr = array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"); for ($i=0;$i<3;$i++) { echo "$b->arr[$i]";//Error } $arr2 = $b->arr; for ($i=0;$i<3;$i++) { echo "$arr2[$i]";//OK } ?>