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

Whitespace

Whitespace refers to spaces, tabulations, and newline characters. Those characters are invisible on a white background, hence the name.

Whitespace is used to format and organize the code, making it more readable.

However, whitespace is generally not significant in terms of parsing; the PHP interpreter usually ignores whitespace. There are some rare situations where the whitespaces have a role: in heredoc syntax, and for formatting floats.

Whitespace is not a notion specific to PHP: other languages have them too. For example, trim() removes whitespace at the beginning and the end of a string value.

<?php

    $heredoc = <<<HEREDOC
        One tab shift
        Here
        HEREDOC;
    
    $concatenation = 1 . 0; // This is 10

    $float = 1.0; // This is 1.0

    //$invalid = 1. 0; // This is a syntax error

?>

Documentation

See Also