1// Examples from PHP Language Reference at 2// http://www.php.net/manual/en/langref.php 3 4<?php 5$var = "Bob"; 6$Var = "Joe"; 7echo "$var, $Var"; // outputs "Bob, Joe" 8 9$4site = 'not yet'; // invalid; starts with a number 10$_4site = 'not yet'; // valid; starts with an underscore 11$t�yte = 'mansikka'; // valid; '�' is ASCII 228. 12?> 13 14<?php 15define("CONSTANT", "Hello world."); 16echo CONSTANT; // outputs "Hello world." 17echo Constant; // outputs "Constant" and issues a notice. 18?> 19 20<?php 21function foo ($arg_1, $arg_2, ..., $arg_n) 22{ 23 echo "Example function.\n"; 24 return $retval; 25} 26 27class Cart 28{ 29 var $items; // Items in our shopping cart 30 31 // Add $num articles of $artnr to the cart 32 33 function add_item ($artnr, $num) 34 { 35 $this->items[$artnr] += $num; 36 } 37 38 // Take $num articles of $artnr out of the cart 39 40 function remove_item ($artnr, $num) 41 { 42 if ($this->items[$artnr] > $num) { 43 $this->items[$artnr] -= $num; 44 return true; 45 } else { 46 return false; 47 } 48 } 49} 50