This site is mobile accessible. Press the "Tap Here" button to use a different font-size.


Smartphone icons created by Freepik - Flaticon

PHP Fundamentals Course

PHP powered

A popular general-purpose scripting language that is especially suited to web development. Fast, flexible and pragmatic, PHP powers everything from your blog to the most popular websites in the world.

Module 1. Introduction

  • 1.1 PHP Intro PHP code is executed on the server.
  • 1.2 PHP Install What Do I Need?
  • 1.3 PHP Syntax A PHP script is executed on the server, and the plain HTML result is sent back to the browser.
  • 1.4 PHP Comments A comment in PHP code is a line that is not executed as a part of the program. Its only purpose is to be read by someone who is looking at the code.
  • 1.5 PHP Variables Variables are "containers" for storing information.
    • 1.5.1 Variables Scope In PHP, variables can be declared anywhere in the script. The scope of a variable is the part of the script where the variable can be referenced/used.
  • 1.6 PHP Echo / Print With PHP, there are two basic ways to get output: echo and print.

Module 2. Data Types

Prerequisites: Module 1. Introduction

  • 2.1 PHP Data Types Variables can store data of different types, and different data types can do different things.
  • 2.2 PHP Strings A string is a sequence of characters, like "Hello world!".
  • 2.3 PHP Numbers In this chapter we will look in depth into Integers, Floats, and Number Strings.
  • 2.4 PHP Math PHP has a set of math functions that allows you to perform mathematical tasks on numbers.
  • 2.5 PHP Constants Constants are like variables except that once they are defined they cannot be changed or undefined.
  • 2.6 PHP Casting Sometimes you need to change a variable from one data type into another, and sometimes you want a variable to have a specific data type. This can be done with casting.
  • 2.7 PHP Magic Constants PHP has nine predefined constants that change value depending on where they are used, and therefor they are called "magic constants". These magic constants are written with a double underscore at the start and the end, except for the ClassName::class constant.

Module 3. Operators and Loops

Prerequisites: Module 2. Data Types

  • 3.1 PHP Operators Operators are used to perform operations on variables and values.
  • 3.2 PHP If...Else...Elseif Conditional statements are used to perform different actions based on different conditions.
  • 3.3 PHP Switch The switch statement is used to perform different actions based on different conditions.
  • 3.4 PHP Loops In the following chapters you will learn how to repeat code by using loops in PHP.
    • 3.4.1 While Loop The while loop - Loops through a block of code as long as the specified condition is true.
    • 3.4.2 Do While Loop The do...while loop - Loops through a block of code once, and then repeats the loop as long as the specified condition is true.
    • 3.4.3 For Loop The for loop - Loops through a block of code a specified number of times.
    • 3.4.4 Foreach Loop The foreach loop - Loops through a block of code for each element in an array.
    • 3.4.5 Break/Continue You have already seen the break statement used in an earlier chapter of this tutorial. It was used to "jump out" of a switch statement. The break statement can also be used to jump out of a loop.
  • 3.5 PHP Functions The real power of PHP comes from its functions. PHP has more than 1000 built-in functions, and in addition you can create your own custom functions.

Module 4. Arrays, Superglobals and Regex

Prerequisites: Module 3. Operators and Loops

  • 4.1 PHP Arrays An array stores multiple values in one single variable:
    • 4.1.1 Indexed Arrays There are two ways to create indexed arrays:
    • 4.1.2 Associative Arrays Associative arrays are arrays that use named keys that you assign to them.
    • 4.1.3 Multidimensional Arrays In the previous pages, we have described arrays that are a single list of key/value pairs. However, sometimes you want to store values with more than one key. For this, we have multidimensional arrays.
    • 4.1.4 Sorting Arrays The elements in an array can be sorted in alphabetical or numerical order, descending or ascending.
  • 4.2 PHP Superglobals Superglobals were introduced in PHP 4.1.0, and are built-in variables that are always available in all scopes.
    • 4.2.1 $GLOBALS $GLOBALS is a PHP super global variable which is used to access global variables from anywhere in the PHP script (also from within functions or methods).
    • 4.2.2 $_SERVER $_SERVER is a PHP super global variable which holds information about headers, paths, and script locations.
    • 4.2.3 $_REQUEST PHP $_REQUEST is a PHP super global variable which is used to collect data after submitting an HTML form.
    • 4.2.4 $_POST PHP $_POST is a PHP super global variable which is used to collect form data after submitting an HTML form with method="post". $_POST is also widely used to pass variables.
    • 4.2.5 $_GET PHP $_GET is a PHP super global variable which is used to collect form data after submitting an HTML form with method="get".
  • 4.3 PHP RegEx A regular expression is a sequence of characters that forms a search pattern. When you search for data in a text, you can use this search pattern to describe what you are searching for.

Module 5. PHP Forms

Prerequisites: Module 4. Arrays, Superglobals and Regex

Module 6. PHP Advanced

Prerequisites: Module 5. PHP Forms

  • 6.1 PHP Date and Time The PHP date() function is used to format a date and/or a time.
  • 6.2 PHP Include Files The include (or require) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement.
  • 6.3 PHP File Handling File handling is an important part of any web application. You often need to open and process a file for different tasks.
  • 6.4 PHP File Open/Read In this chapter we will teach you how to open, read, and close a file on the server.
  • 6.5 PHP File Create/Write In this chapter we will teach you how to create and write to a file on the server.
  • 6.6 PHP File Upload With PHP, it is easy to upload files to the server. However, with ease comes danger, so always be careful when allowing file uploads!
  • 6.7 PHP Cookies A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer.
  • 6.8 PHP Sessions A session is a way to store information (in variables) to be used across multiple pages. Unlike a cookie, the information is not stored on the users computer.
  • 6.9 PHP Filters PHP filters are used to validate and sanitize external input.
  • 6.10 PHP Filters Advanced Validate an Integer Within a Range, Validate IPv6 Addresses, Validate URL - Must Contain QueryString, Remove Characters With ASCII Value > 127
  • 6.11 PHP Callback Functions A callback function (often referred to as just "callback") is a function which is passed as an argument into another function. Any existing function can be used as a callback function. To use a function as a callback function, pass a string containing the name of the function as the argument of another function.
  • 6.12 PHP JSON JSON stands for JavaScript Object Notation, and is a syntax for storing and exchanging data. Since the JSON format is a text-based format, it can easily be sent to and from a server, and used as a data format by any programming language.
  • 6.13 PHP Exceptions An exception is an object that describes an error or unexpected behaviour of a PHP script. Exceptions are thrown by many PHP functions and classes.

Module 7. PHP OOP

Prerequisites: Module 6. PHP Advanced

  • 7.1 PHP What is OOP From PHP5, you can also write PHP code in an object-oriented style. Object-Oriented programming is faster and easier to execute.
  • 7.2 PHP Classes/Objects A class is a template for objects, and an object is an instance of class.
  • 7.3 PHP Constructor A constructor allows you to initialize an object's properties upon creation of the object.
  • 7.4 PHP Destructor A destructor is called when the object is destructed or the script is stopped or exited.
  • 7.5 PHP Access Modifiers Properties and methods can have access modifiers which control where they can be accessed.
  • 7.6 PHP Inheritance Inheritance in OOP = When a class derives from another class.
  • 7.7 PHP Class Constants Constants cannot be changed once it is declared. Class constants can be useful if you need to define some constant data within a class.
  • 7.8 PHP Abstract Classes Abstract classes and methods are when the parent class has a named method, but need its child class(es) to fill out the tasks. An abstract class is a class that contains at least one abstract method. An abstract method is a method that is declared, but not implemented in the code.
  • 7.9 PHP Interfaces Interfaces allow you to specify what methods a class should implement.
  • 7.10 PHP Traits Traits are used to declare methods that can be used in multiple classes. Traits can have methods and abstract methods that can be used in multiple classes, and the methods can have any access modifier (public, private, or protected).
  • 7.11 PHP Static Methods Static methods can be called directly - without creating an instance of the class first.
  • 7.12 PHP Static Properties Static properties can be called directly - without creating an instance of a class.
  • 7.13 PHP Namespaces Namespaces are qualifiers that solve two different problems:
  • 7.14 PHP Iterables An iterable is any value which can be looped through with a foreach() loop. The iterable pseudo-type was introduced in PHP 7.1, and it can be used as a data type for function arguments and function return values.

Module 8. MySQL Database

Prerequisites: Module 7. PHP OOP

  • 8.1 MySQL Database With PHP, you can connect to and manipulate databases. MySQL is the most popular database system used with PHP.
  • 8.2 MySQL Connect PHP 5 and later can work with a MySQL database using: MySQLi extension (the "i" stands for improved), PDO (PHP Data Objects)
  • 8.3 MySQL Create DB A database consists of one or more tables.
  • 8.4 MySQL Create Table A database table has its own unique name and consists of columns and rows.
  • 8.5 MySQL Insert Data After a database and a table have been created, we can start adding data in them.
  • 8.6 MySQL Get Last ID If we perform an INSERT or UPDATE on a table with an AUTO_INCREMENT field, we can get the ID of the last inserted/updated record immediately.
  • 8.7 MySQL Insert Multiple Multiple SQL statements must be executed with the mysqli_multi_query() function.
  • 8.8 MySQL Prepared Prepared statements are very useful against SQL injections.
  • 8.9 MySQL Select Data The SELECT statement is used to select data from one or more tables:
  • 8.10 MySQL Where The WHERE clause is used to filter records. The WHERE clause is used to extract only those records that fulfill a specified condition.
  • 8.11 MySQL Order By The ORDER BY clause is used to sort the result-set in ascending or descending order. The ORDER BY clause sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword.
  • 8.12 MySQL Delete Data The DELETE statement is used to delete records from a table:
  • 8.13 MySQL Update Data The UPDATE statement is used to update existing records in a table:
  • 8.14 MySQL Limit Data MySQL provides a LIMIT clause that is used to specify the number of records to return. The LIMIT clause makes it easy to code multi page results or pagination with SQL, and is very useful on large tables. Returning a large number of records can impact on performance.

Module 9. PHP XML

Prerequisites: Module 7. PHP OOP

  • 9.1 PHP XML Parsers The XML language is a way to structure data for sharing across websites. Several web technologies like RSS Feeds and Podcasts are written in XML. XML is easy to create. It looks a lot like HTML, except that you make up your own tags.
  • 9.2 PHP SimpleXML Parser impleXML is a PHP extension that allows us to easily manipulate and get XML data. SimpleXML provides an easy way of getting an element's name, attributes and textual content if you know the XML document's structure or layout.
  • 9.3 PHP SimpleXML - Get SimpleXML is a PHP extension that allows us to easily manipulate and get XML data.
  • 9.4 PHP XML Expat The built-in XML Expat Parser makes it possible to process XML documents in PHP.
  • 9.5 PHP XML DOM The built-in DOM parser makes it possible to process XML documents in PHP.

Module 10. PHP - AJAX

Prerequisites: Module 7. PHP OOP

  • 10.1 AJAX Intro AJAX is about updating parts of a web page, without reloading the whole page. AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.
  • 10.2 AJAX PHP AJAX is used to create more interactive applications.
  • 10.3 AJAX Database AJAX can be used for interactive communication with a database.
  • 10.4 AJAX XML AJAX can be used for interactive communication with an XML file.
  • 10.5 AJAX Live Search AJAX can be used to create more user-friendly and interactive searches.
  • 10.6 AJAX Poll The following example will demonstrate a poll where the result is shown without reloading.

I like your feedback. Take my poll.

PHP Reference

Course Outline


Quiz