get all arguments starting with sub 1 php code example

Example 1: php get all function arguments

<?php
function foo()
{
    $numargs = func_num_args();
    echo "Number of arguments: $numargs \n";
    if ($numargs >= 2) {
        echo "Second argument is: " . func_get_arg(1) . "\n";
    }
    $arg_list = func_get_args();
    for ($i = 0; $i < $numargs; $i++) {
        echo "Argument $i is: " . $arg_list[$i] . "\n";
    }
}

foo(1, 2, 3);
?>

Example 2: variable args php

function some_function(...$args): void {
  $val1 = $args[0];
  // Access as normal index array
}

Tags:

Php Example