Easy To Learning
  • Login
  • Sign Up
  • Q&A
  • Home
  • Php Tutorial
  • MySql Tutorial
  • Object-Oriented Programming
  • Java Tutorial
  • HTML Tutorial
  • React JS Tutorials
  • Free Projects
  • Blogs & Articles
  • Others
    • About Us
    • Contact Us
Variable Argument Function In PHP
Easy To Learning

Education Needs Complete Solution

Online Ask Question Question And Answer
  1. Home
  2. PHP Tutorials
  3. Variable Argument Function In PHP

PHP Tutorial

Basic PHP Fundamentals

  • PHP Tutorial Content
  • PHP Introduction
  • PHP History
  • Uses of PHP
  • PHP Features
  • What Is PHP
  • PHP Installation And Software Requirements
  • How To Install Wamp Server
  • How To Install Xampp Server
  • Php Syntax
  • PHP Variables
  • PHP Data Types
  • PHP Constants
  • PHP Echo And Print
  • PHP Operators
  • PHP Assignment Operators
  • PHP String And Logical Operators
  • Operators Categories
  • PHP Comments
  • PHP $ And $$ Variables
  • Super Global Variables

PHP Control Statement

  • PHP Control Structure
  • PHP If Statement
  • If Elseif Statement In PHP
  • Switch Statement In PHP
  • Break Statement In PHP
  • If Elseif Else Statement
  • Continue Statement In PHP

Php Loops

  • What Is Loop
  • For Loop In PHP
  • PHP Foreach Loop
  • PHP While Loop
  • Do While Loop

PHP Arrays

  • PHP Arrays
  • Indexed Arrays
  • Associative Array
  • Multidimensional Arrays
  • Array Functions
  • Array Constants
  • List of Array Functions
  • Array Functions First Exercise

Php String

  • String In PHP
  • PHP String Functions

PHP Functions

  • PHP Functions
  • PHP Parameterized Function
  • PHP Call By Value
  • Call By Reference In PHP
  • Default Argument Values Function In PHP
  • Variable Argument Function In PHP
  • Recursive Function In PHP
  • Math Function In PHP
  • Math Function Examples

PHP Form

  • Form Handling In PHP

PHP Include

  • Include File In PHP

PHP State Management

  • Cookies In PHP
  • Session In PHP

PHP File System

  • File Handling In PHP
  • Open Files In PHP
  • Read Files In PHP
  • Write Files In PHP
  • Delete Files In PHP
  • Append To Files In PHP

PHP Upload & Download

  • File Upload In PHP
  • Download File In PHP

PHP Mail System

  • Mail System In PHP
  • Mail With Attachment In PHP

Basic PHP Program

  • Php Programs
  • Sum Of Digits
  • PHP Even Odd Program
  • Prime Number Program
  • Table Of Number Program
  • Factorial Of A Number
  • Armstrong Number
  • Palindrome Number
  • Fibonacci Series

Variable Argument Function In PHP

PHP supports variable-length argument function. It means you can pass 0, 1 or n number of arguments in the function. To do so, you need to use 3 ellipses (dots) before the argument name.

A simple example of a PHP variable-length argument function.

Example

<?php  
function addCal(...$numbers) {  
    $sum = 0;  
    foreach ($numbers as $n) {  
        $sum += $n;  
    }  
    return $sum;  
}  
echo add(1,2,3,4);  
?>  

Output:10

1. func_num_args()

  • This function returns the number of the argument passed into the current user-defined function. The return type is an integer.
  • Func_num_args() will generate a warning if called from outside of a user-defined function.

Syntax

int func_num_args(void)

Example

<?php
   function callMe()
   {
      $value = func_num_args();
      echo "Number of arguments : ".$value;
   }
   callMe(1,2,3,4);
?>

Output  :  

Number of arguments : 4

2. func_get_arg()

  • Returns an item from the argument list.

Syntax

mixed func_get_arg(int arg_num)
  • Returns the argument which is at the arg_num’th offset into a user-defined function’s argument list.
  • The function argument is counted starting from zero.
  • func_get_arg() will generate a warning if called from outside of a function definition. This function cannot be used directly as a function parameter instead, its result may be assigned to a variable, which can then be passed to the function.

Example

<?php
 function callMe()
 {
   $num_arg = func_num_args();
   echo "Number of arguments : ".$num_arg."<br/>";
   if($num_arg >= 2)
   {
     echo "Seccond arguments is : ".func_get_arg(1);
   }
 }
 callMe(1,2,3,4);
?>

Output  :

Number of arguments : 4

Seccond arguments is : 2

3. func_get_args()

  • Returns the array of arguments passed into the current user-defined function.

Syntax

array func_get_args(void)

Example

<?php
  function callMe()
  {
    $num_args = func_num_args();
    if($num_args > 0)
    {
      $num = func_get_args();
      foreach($num as $value)
      {
        echo $value."<br/>";
      }
    }
  }
 callMe("Hello","World");
?>

Output  :

Hello

World

Series: PHP Tutorials Hub
All Topics
Free Download Projects
Previous Chapter
Next Chapter

Ask a Question

Have a coding query or doubt? Ask here and get help from our community.

500 characters remaining
Submitting...
Free Download Projects
Join Telegram Group Join WhatsApp Group
Related Topics:
PHP Variable Length Argument Function PHP Variable Arguments php func_get_args php ellipsis operator php splat operator php functions optional parameters php named parameters php optional arguments

Member Sign In

Forgot?
Signing in...

Don't have an account? Register here

Create Free Account

Register Captcha
Registering...

Already have an account? Sign In

Ask a Question

500 characters remaining
Submitting...

About Easy To Learning

Easy To Learning is a comprehensive programming learning portal offering free, practical, developer-driven tutorials for PHP, Java, Python, Spring, MySQL, CSS, Bootstrap, CakePHP, and more.

Explore community-contributed questions and answers, and download ready-to-run source code projects.

Quick Links

  • Home
  • Questions & Answers
  • Download Projects
  • Blog & Articles
  • Member Login

Community

  • Telegram Group
  • WhatsApp Community
  • Ask a Question
  • Join as Member

Connect With Us

Stay updated with our newest programming tutorials and free open source projects.

© 2026 Easy To Learning. All Rights Reserved.