HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to PHPVariablesData TypesOperatorsStringsArraysAssociative ArraysConditions (if / else)Loops (for / foreach / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables
🔢 Numbers & Math
✍️ String
📋 Array
🔁 Condition & Loop
🧩 Function
🔄 Type & Conversion

PHP lessons

Server-side classic

PHP is a language born for the web. It started in 1995 as a personal homepage tool and today it powers a huge portion of the sites on the internet. Countless applications written with WordPress, Drupal, Joomla, and Laravel run on PHP.

What sets PHP apart is that it runs on the server side and generates HTML: when a visitor requests a page, the PHP code runs on the server, and the result goes to the browser as ready HTML. That's why opening a PHP file directly in the browser doesn't work; it requires a server.

The language has a bad reputation, and part of it was justified: older versions were full of inconsistencies and patterns that invited security vulnerabilities. However, with PHP 7 and 8, the language recovered significantly — performance increased several folds, type declarations were introduced, and error handling was streamlined. Modern PHP written today looks very little like it did a decade ago.

📖 Command Reference→
  • •

    Introduction to PHP

    First step into the server-side language PHP: printing with echo, variables with $, and embedding variables into text.

    →
  • •

    Variables

    Creating variables with $, naming, and constants (define/const).

    →
  • •

    Data Types

    string, int, float, bool types; learning types with gettype and type casting.

    →
  • •

    Operators

    Math (+ - * / % **), comparison (== === < >), logical (&& ||), and concatenation (.) operators.

    →
  • •

    Strings

    Length, case conversion, replacement, splitting (explode), and joining (implode).

    →
  • •

    Arrays

    Creating arrays, element access, adding, counting (count), and iterating with foreach.

    →
  • •

    Associative Arrays

    Storing and traversing structured data using key=>value mappings.

    →
  • •

    Conditions (if / else)

    Decision making with if-elseif-else, comparison, logic, and the ternary operator (?:).

    →
  • •

    Loops (for / foreach / while)

    Specific repetitions with for, traversing arrays with foreach, conditional repetition with while.

    →
  • •

    Functions

    Defining functions with function, parameters, return, and default values.

    →

What you will learn

  • To output text with echo and define variables with a dollar sign
  • To store data using arrays and associative arrays
  • To dynamically generate page content with conditions and loops
  • To write functions and split code across files
  • To securely receive data coming from a form
  • To connect to a database with PDO and execute queries

Who is this for?

  • Those who want to develop WordPress themes or plugins
  • Those who want to quickly set up a web backend that performs well
  • Those planning to transition to a modern PHP framework like Laravel

When to use?

For content sites, e-commerce, enterprise web applications, and any work in the WordPress ecosystem, PHP is the natural choice; it's the easiest language to set up on shared hosting.

It is not suitable for real-time socket applications, heavy computations, and mobile apps. Desktop software is also not written with PHP.

Frequently asked questions

Is PHP dead?

No. Its share in new projects has decreased, but a vast majority of working websites are written in PHP, and WordPress alone constitutes a massive market. Maintenance, customization, and new module development jobs will continue for years.

Which version should I target while learning PHP?

PHP 8 and above. Functions like mysql_query that you will see in tutorials written with PHP 5 have been removed and are not secure. Use PDO or MySQLi for the database; the examples on this site use modern syntax.

Why can't I open a PHP file in the browser?

PHP runs on the server side. When you double-click and open the file, the browser sees the code as text. To run it, you need to set up a server environment on your computer (XAMPP, Laragon, or PHP's built-in server) and request the file through that server.

What do I need to know before learning Laravel?

Being able to write variables, arrays, functions, and classes in plain PHP; being able to process data coming to a form and write it to a database. Laravel makes these fundamentals very easy but doesn't teach the fundamentals; if you start by skipping them, you won't be able to resolve error messages.

Summary

PHP is one of the most common languages for web backend, and with PHP 8, it has become a modern language. In this tutorial, we progress from starting with echo to arrays, functions, form processing, and database connection.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code