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

Useless

Some piece of code is useless when it doesn’t bring any feature to the code.

It may be the case of double checks, where a characteristic is checked twice in a row; or when the same operation is repeated multiple times, yet is idempotent.

It is also the case of unused calculations: they are processed, stored, but ultimately, not combined with anything else.

<?php

function trumpet(array $array) {
    if (!empty($array)) {
        // foreach() checks automatically the array for elements, and skips the loop when the array is empty.
        foreach($array as $tusk) {
            doSomething();
        }
    }
}

// trumpet is defined and called
$result = trumpet([]);

?>

Documentation

See Also