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

Variadic

Three dots, aka ellipsis, is an operator to spread or collect array values.

Applied to an array, it spreads the values of the array as distinct elements.

Used in a function signature, it collects all the values into one array.

<?php

    $array = [1, 2, 3];

    // same as trumpet(0, 1,2, 3);
    trumpet(0, ...$array);


    function trumpet($special, ...$others) {
        // with the above call
        // $special === 0
        // $others === [1, 2, 3, 4]
    }

?>

Documentation

See Also