PHPExamples
PHP Syntax
Write text to the output using PHPKeywords, classes, functions, and user-defined functions ARE NOT case-sensitiveVariable names ARE case-sensitive
PHP Comments
Syntax for single-line commentsSyntax for multi-line commentsUsing comments to leave out parts of the code
PHP Variables
Create different variablesTest global scope (variable outside function)Test local scope (variable inside function)Use the global keyword to access a global variable from within a functionUse the $GLOBALS[] array to access a global variable from within a functionUse the static keyword to let a local variable not be deleted after execution of function
PHP Echo and Print
Display strings with the echo commandDisplay strings and variables with the echo commandDisplay strings with the print commandDisplay strings and variables with the print command
PHP Data Types
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()
PHP Numbers
Check if the type of a variable is integerCheck if the type of a variable is floatCheck if a numeric value is finite or infiniteInvalid calculation will return a NaN valueCheck if a variable is numericCast float and string to integer
PHP Math
Find the value of PIFind the lowest and highest value in a list of argumentsFind the absolute (positive) value of a numberFind the square root of a numberRound a floating-point number to its nearest integerGenerate a random numberGenerate a random number between 10 and 100
PHP Constants
Case-sensitive constant nameCase-insensitive constant nameCreate a Array constant with define()Use a constant inside a function (when it is defined outside the function)
PHP Operators
Arithmetic operator: Addition (+)Arithmetic operator: Subtraction (-)Arithmetic operator: Multiplication (*)Arithmetic operator: Division (/)Arithmetic operator: Modulus (%)Assignment operator: x = yAssignment operator: x += yAssignment operator: x -= yAssignment operator: x *= yAssignment operator: x /= yAssignment operator: x %= yComparison 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 (<=)Comparison operator: Spaceship (<=>)Increment operator: ++$xIncrement operator: $x++Decrement operator: --$xDecrement operator: $x--Logical operator: andLogical operator: orLogical operator: xorLogical operator: && (and)Logical operator: || (or)Logical operator: notString operator: Concatenation of $txt1 and $txt2String operator: Appends $txt2 to $txt1Array operator: Union (+)Array operator: Equality (==)Array operator: Identity (===)Array operator: Inequality (!=)Array operator: Inequality (<>)Array operator: Non-identity (!==)Conditional assignment operator: Ternary (?:)Conditional assignment: Null coalescing (??)
PHP If...Else and Switch Statements
PHP While and For Loops
The while loopThe do...while loopAnother do...while loopThe for loopThe foreach loopThe break statement in a loopThe continue statement in a loop
PHP Functions
Create a functionFunction with one argumentFunction with two argumentsFunction with default argument valueFunction that returns a valueReturn type declarationsPassing arguments by reference
PHP Arrays
Indexed arrayscount() - Return the length of an arrayLoop through an indexed arrayAssociative arraysLoop through an associative array
PHP Multidimensional Arrays
Multidimensional Arrays explained
PHP Sorting Arrays
sort() - Sort array in ascending alphabetical ordersort() - Sort array in ascending numerical orderrsort() - Sort array in descending alphabetical orderrsort() - Sort array in descending numerical orderasort() - Sort array in ascending order, according to valueksort() - Sort array in ascending order, according to keyarsort() - Sort array in descending order, according to valuekrsort() - 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 Regular Expressions
Do a case-insensitive search for "w3schools" in a stringDo a case-insensitive count of the number of occurrences of "ain" in a stringReplace "Microsoft" with "W3Schools" in a string
PHP Form Validation
PHP Date and Time
Format today's date in several waysAutomatically update the copyright year on your websiteOutput the current time (server time)Set timezone, then output current timeCreate a date and time from a number of parameters in mktime()Create a date and time from the strtotime() functionCreate more dates/times from strtotime()Output the dates for the next six SaturdaysOutput the number of days until 4th of July
PHP Include Files
Use include to include "footer.php" in a pageUse include to include "menu.php" in a pageUse include to include "vars.php" in a pageUse include to include a non-existing fileUse require to include a non-existing file
PHP File Handling
PHP File Open/Read/Close
Use fopen(), fread(), and fclose() to open, read, and close a fileUse fgets() to read a single line from a fileUse feof() to read through a file, line by line, until end-of-file is reachedUse fgetc() to read a single character from a file
File Open/Read/Close explained
PHP Cookies
PHP Sessions
Start a sessionGet session variable valuesGet all session variable valuesModify a session variableDestroy a session
PHP Filters
Use filter_list() to list what the PHP filter extension offersSanitize a stringValidate an integerValidate an integer that is 0Validate an IP addressSanitize and validate an email addressSanitize and validate a URL
PHP JSON
Encode an associative array into a JSON objectDecode JSON data into a PHP objectAccess the values from a PHP objectLoop through the values of a PHP object
PHP Exceptions
Throw an ExceptionUse try..catch to show a message when an exception is thrownUse finallyOutput information about an exception that was thrown
PHP Classes/Objects
Define a class and an objectUsing the $this keywordUsing the instanceof keywordCreating a constructorCreating a destructorInheritanceClass constantsAbstract classesTraitsStatic methodStatic property
PHP OOP (Classes/Objects) explained
PHP Select Data From MySQL
Select data with MySQLi (Object-oriented)Select data with MySQLi (Procedural)Put the resut in an HTML table (Object-oriented)Select data with PDO (+ Prepared statements)
Select Data From MySQL explained
PHP SimpleXML Parser
Use simplexml_load_string() to read XML data from a stringUse simplexml_load_file() to read XML data from a fileGet node valuesGet node values of specific elementsGet node values - loopGet attribute valuesGet attribute values - loop

