Category: PHP

PHP Function

PHP Function Function syntax function function_name() { php code; } Function example <html> <body> <?php function Test() { echo "I like PHP functions!"; } Test(); ?> </body> </html> Result I like PHP functions! Function with parameters <html> <body> <?php function pFunction($p_name,...

PHP Arrays

PHP Arrays An array in PHP is a type that associates values to keys. This type can be an array, list, hash table, dictionary, collection, stack, queue. Simple array example <html> <body> <?php $courses = array("PHP", "MySQL"); echo "I learn "...

PHP For

PHP For For syntax for (initialization; condition; incrementation) { execute statement } For example <html> <body> <?php for ($n = 1; $n <= 5; $n++) { echo "<br />"; echo "n = ", $n; } ?> </body> </html> Result n =...

PHP Do…While

PHP Do…While Do…While syntax do{ execute statement }while (expression is true) ; Do…While example <html> <body> <?php $n = 1; do{ echo "<br />"; echo "n = ", $n++; } while ($n <= 3) ; ?> </body> </html> Result n =...

PHP While

PHP While While syntax while (expression is true) { execute statement } While example <html> <body> <?php $x = 1; while ($x <= 3) { echo "<br />"; echo "x = ", $x++; } ?> </body> </html> Result x = 1...