X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

PHP Examples


PHP Syntax

Write text to the output using PHP
Add comments in PHP
Keywords, classes, functions, and user-defined functions ARE NOT case-sensitive
Variable names ARE case-sensitive

Examples explained


PHP Variables

Create different variables
Test global scope (variable outside function)
Test local scope (variable inside function)
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

Examples explained


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

Examples explained


PHP Data Types

PHP string
PHP integer
PHP float
PHP array
PHP object
PHP NULL value

Examples explained


PHP Strings

Get the length of a string - strlen()
Count the number of words in a string - str_word_count()
Reverse a string - strrev()
Search for a specific text within a string - strpos()
Replace text within a string - str_replace()

Examples explained


PHP Constants

Case-sensitive constant name
Case-insensitive constant name

Examples explained


PHP Operators

Arithmetic operator: Addition (+)
Arithmetic operator: Subtraction (-)
Arithmetic operator: Multiplication (*)
Arithmetic operator: Division (/)
Arithmetic operator: Modulus (%)
Assignment operator: x = y
Assignment operator: x += y
Assignment operator: x -= y
Assignment operator: x *= y
Assignment operator: x /= y
Assignment operator: x %= y
Comparison operator: Equal (==)
Comparison operator: Identical (===)
Comparison operator: Not equal (!=)
Comparison operator: Not equal (<>)
Comparison operator: Not identical (!==)
Comparison operator: Greater than (>)
Comparison operator: Less than (<)
Comparison operator: Greater than or equal (>=)
Comparison operator: Less than or equal (<=)
Increment operator: ++$x
Increment operator: $x++
Decrement operator: --$x
Decrement operator: $x--
Logical operator: and
Logical operator: or
Logical operator: xor
Logical operator: && (and)
Logical operator: || (or)
Logical operator: not
String operator: Concatenation of $txt1 and $txt2
String operator: Appends $txt2 to $txt1
Array operator: Union (+)
Array operator: Equality (==)
Array operator: Identity (===)
Array operator: Inequality (!=)
Array operator: Inequality (<>)
Array operator: Non-identity (!==)

Examples explained


PHP If...Else and Switch Statements

The if statement
The if...else statement
The if...elseif...else statement
The switch statement

Examples explained


PHP While and For Loops

The while loop
The do...while loop
Another do...while loop
The for loop
The foreach loop

Examples explained


PHP Functions

Create a function
Function with one argument
Function with two arguments
Function with default argument value
Function that returns a value

Examples explained


PHP Arrays

Indexed arrays
count() - Return the length of an array
Loop through an indexed array
Associative arrays
Loop through an associative array

Examples explained


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

Examples explained


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

Examples explained


PHP Form Validation

Complete code for PHP Form Validation

Example explained



Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook