Whitespace means spaces, tabs and line breaks. In PHP code, most whitespace does not matter. These two programs do exactly the same thing:
<?php
$a=1;$b=2;echo $a+$b;
3
<?php
$a = 1;
$b = 2;
echo $a + $b;
3
The second version is much easier to read. Use whitespace for people, not for PHP.
Where whitespace does matter
You cannot put a space in the middle of a name.
<?php
$my name = "Ravi"; // wrong: a space splits the name in two
$my_name = "Ravi"; // correct
Whitespace inside a string is part of the string.
<?php
echo "a b";
a b
Indentation
PHP does not need indentation, but you should always use it. The common style uses 4 spaces per level.
<?php
$age = 20;
if ($age >= 18) {
echo "Adult";
} else {
echo "Minor";
}
Adult
Whitespace outside PHP tags is output
Anything outside <?php ... ?> is sent to the browser. A space or blank line before the opening tag, or after a closing tag, becomes part of the page.
That is why a PHP-only file should start with <?php on the very first line and should not have a closing ?> tag. PHP Tags explains the reason.