Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Variables

Variables are used to store and manipulate data. They are containers that hold values, such as numbers, strings, arrays, objects, and more. Variables are an essential component of programming, allowing to store and retrieve information as needed throughout the code.

Variables must start with a dollar sign $ followed by the variable name. The name should begin with a letter or an underscore and can contain letters, numbers, and underscores. PHP variable names are case-sensitive.

PHP is a loosely typed language, which means there is no need to explicitly declare the type of a variable. PHP determines the variable’s type based on the assigned value.

<?php

    $a = 'b';
    // more code
    echo $a; // displays b

?>

Documentation

See Also