This tutorial covers: PHP basics such as: tags, comments, echo, print, echo shortcut and difference between echo and print and why to use PHP?
Learn how to test PHP scripts on your laptop or computer by installing PHP, Apache and MySQL. You'll also learn how to write a PHP script using a code editor or IDE.
Variables in PHP are identified by a dollar sign ($) followed by the variable name. Variables don't need to be declared, and they have no type until they are assigned a value.
A string is any series of characters enclosed in single (‘) or double (“) quotes, or that you create using special heredoc or nowdoc syntax.
A constant is a variable with a value that cannot be changed by the script. Constants may not be redefined or undefined once they have been set. PHP provides two methods for creating constants: the const modifier and the define() function.
In this tutorial we'll discuss the most fundamental parts of PHP programming language: variable assignment, expressions and operators.
In PHP, you can initialize a variable with an integer value, add a float value to it, thereby turning it into a float, then join it onto a string value to produce a string.
PHP provides several mechanisms to allow variables of one type to be considered as another type. Variables can be explicitly converted to another type with the settype, strval, intval, boolval and floatval functions.
Namespaces help to avoid naming collisions between libraries and shared code. A namespace will encapsulate the codes (classes, functions and constants) inside it so that they don’t conflict if the same declared elsewhere.
Learn how to load classes files when they are required using PHP's autoloading feature.
A trait defines methods intended to be used by multiple classes. The structure of a trait is the same as a class, except that it’s declared using the keyword trait instead of class.
Any function containing yield is a generator function. A generator is used to generate a series of values which returned with yield statement.
A lambda function (also commonly referred to as an anonymous function) is a function that was declared without any named identifier to refer to it. A closure is a lambda which closes over the environment in which it was defined.
PHP 7 now offers the possibility to strict type variables and function signatures, known as “Type declarations” (“type hints” in PHP 5) and “Return type declarations”.
Learn how to enable strict mode in PHP. In strict mode, only a variable of exact type of the “type declaration” will be accepted, or a TypeError will be thrown.
The ternary operator can replace a single if/else clause. It uses three expressions, if the first one is evaluated to true, then the second expression is returned, otherwise the third one is returned.
PHP 7 introduced “null coalesce operator (??)” to check whether a variable contains value , or returns a default value. This operator ?? is ideal to use with $_POST and $_GET for getting input from users or urls.
PHP 5.3.0 introduced the goto statement, which performs a jump to a specified label (line) within the same file.