Back to Developer Roadmap

Named Arguments

src/data/roadmaps/php/content/named-arguments@RkNjYva8o_jXp9suz5YdG.md

4.0733 B
Original Source

Named Arguments

Named arguments in PHP, introduced with PHP 8.0, allow you to specify the values of required parameters by their names, instead of their position in the function call, thus making your code more readable, reducing mistakes, and allowing for unimportant arguments to be skipped. Here's an array_fill() function using named arguments:

<?php
$a = array_fill(start_index: 0, count: 100, value: 50);

In this code snippet, the parameters are passed by their names ('start_index', 'count', 'value'), not by their order in the function definition.

Visit the following resources to learn more: