PHP Examples
PHP Syntax
Write text to the output using PHP
Add comments in PHP
User-defined functions, classes, and keywords ARE NOT case-sensitive
Variable names ARE case-sensitive
PHP Variables
Create different variables
Test local (inside function) and global (outside function) scope
Use the global keyword to access a global variable from within a function
Use the $GLOBALS[] array to access a global variable from within a function
Use the static keyword to let a local variable not be deleted after execution of function
PHP Echo and Print
Display strings with the echo command
Display strings and variables with the echo command
Display strings with the print command
Display strings and variables with the print command
PHP Data Types
PHP strings
PHP integers
PHP floating point numbers
PHP arrays
PHP objects
PHP NULL value
PHP String Functions
strlen() - Return the length of a string, in characters
strpos() - Search for a specified character or text within a string
PHP Constants
Create a case-sensitive constant
Create a case-insensitive constant
PHP Operators
Arithmetic operators
Assignment operators
String operators
Increment/Decrement operators
Comparison operators
Array operators
PHP If...Else and Switch Statements
The if statement
The if...else statement
The if...elseif...else statement
The switch statement
PHP While and For Loops
The while loop
The do...while loop
Another do...while loop
The for loop
The foreach loop
PHP Functions
Create a function
Function with one argument
Function with two arguments
Function with default argument value
Function that returns a value
PHP Arrays
Indexed arrays
count() - Return the length of an array
Loop through an indexed array
Associative arrays
Loop through an associative array
PHP Sorting Arrays
sort() - Sort array in ascending alphabetical order
sort() - Sort array in ascending numerical order
rsort() - Sort array in descending alphabetical order
rsort() - Sort array in descending numerical order
asort() - Sort array in ascending order, according to value
ksort() - Sort array in ascending order, according to key
arsort() - Sort array in descending order, according to value
krsort() - Sort array in descending order, according to key
PHP Superglobals
$GLOBAL - Used to access global variables from anywhere in the PHP script
$_SERVER - Holds information about headers, paths, and script locations
$_REQUEST - Used to collect data after submitting an HTML form
$_POST - Used to collect form data after submitting an HTML form. Also used to pass variables
$_GET - Collect data sent in the URL
PHP Form Validation
Complete code for PHP Form Validation
Your suggestion:
Thank You For Helping Us!
Your message has been sent to W3Schools.