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

Named Parameters

Named parameters, also known as named arguments allow to pass arguments to a function or method by specifying the parameter name along with the corresponding value, rather than relying on the order of the parameters.

In traditional positional parameter passing, the values are provided to a function in the order in which the parameters are defined. However, with named parameters, the parameter to which a value is passed, is explicitly stated.

<?php

    function trumpet($a, $b) {
        return $a - $b;
    }

    echo trumpet(2, 3);  // return -1
    echo trumpet(3, 2);  // return 1

    echo trumpet(a: 2, b: 3);  // return -1
    echo trumpet(b: 2, a: 3);  // return 1

?>

Documentation

See Also