Skip to content
Justice Tech School

Named and Variadic Arguments

Named arguments choose parameters by name. ... collects many arguments.

Example
function box(int $w, int $h = 1) { return $w * $h; }
echo box(h: 3, w: 2), "\n";
function sum(...$n) { return array_sum($n); }
echo sum(1, 2, 3);

Result

6
6

Exercise

Collect args.

function f($n) {}

Quiz Test

What do named arguments allow?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.