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

Neutral Element

A neutral element is a piece of data which has no effect with a particular operation.

For example, 0 is the neutral element for the addition, as 0 + $a is the same as $a + 0 and the same as $a, without any type change.

The neutral element for the multiplication is 1; the neutral element for the concatenation is the empty string ''.

It is usually possible to define a neutral element for any operation or method call. For objects, they are called null objects, as they could replace the null scalar value.

<?php

    $a = 10;
    
    $a *= 1; // this does nothing
    $a += 1; // this does nothing

?>

Documentation

See Also