func_get_arg
<<<
func_get_args func_num_args
>>>

8.40 Fonctions
8 Référence des fonctions
 Manuel PHP

Introduction
Pré-requis
Installation
Configuration à l'exécution
Constantes pré-définies
call_user_func_array
call_user_func
create_function
func_get_arg
->func_get_args
func_num_args
function_exists
get_defined_functions
register_shutdown_function
register_tick_function
unregister_tick_function

8.40.10 func_get_args() Retourne les arguments d'une fonction sous forme de tableau

[ Exemples avec func_get_args ]   PHP 4 , PHP 5

array  func_get_args ( void )

func_get_args retourne un tableau dont chaque élément est une copie du membre correspondant de la liste d'arguments de la fonction. func_get_args générera une alerte si elle est appelée hors d'une fonction. Cette fonction ne peut être directement utilisée en tant que paramètre d'une fonction. A la place, son résultat peut être assigné à une variable, qui peut être passée à une fonction.

Note

Cette fonction retourne uniquement une copie des arguments passés, et ne compte pas en tant qu'arguments par défaut (non passés).

Exemple avec func_get_args

<?php
function foo()
{
  
$numargs = func_num_args();
  echo
"Nombre d'arguments: $numargs<br />\n";
  if (
$numargs >= 2) {
     echo
"Le second argument est : " . func_get_arg (1) . "<br />\n";
  }
  
$arg_list = func_get_args();
  for (
$i = 0; $i < $numargs; $i++) {
     echo
"L'argument $i est : " . $arg_list[$i] . "<br />\n";
  }
}

foo(1, 2, 3);
?>

func_get_arg peut être utilisé conjointement à func_num_args et func_get_args pour permettre aux fonctions utilisateurs d'accepter un nombre variable d'arguments.

<< func_get_args >>
func_get_arg Fonctions func_num_args