Named Arguments
Last updated
What is 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.
Free resources to learn Named Arguments
- Official docsNamed Arguments
More in stage 5: Functions
Named Arguments: common questions
Can I learn Named Arguments in Hindi?
This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain Named Arguments in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.
Is this Named Arguments tutorial for beginners?
It is lesson 33 of 120 in the free PHP roadmap, in stage 5, Functions. If you are new to PHP, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.