★ wanayoo — archive 1999 http://www.php.net/manual/function.func-get-arg.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Misc.
Quick Reference
Misc.
* connection_aborted
* connection_status
* connection_timeout
* define
* defined
* die
* eval
* exit
* func_get_arg
* func_get_args
* func_num_args
* function_exists
* get_browser
* ignore_user_abort
* iptcparse
* leak
* pack
* register_shutdown_function
* serialize
* sleep
* uniqid
* unpack
* unserialize
* usleep
Manual: func_get_arg
View the source code for this pageSearch the site



Previous page
 exit
func_get_args 
Next page


func_get_arg

func_get_arg -- Return an item from the argument list

Description

int 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. Function arguments are counted starting from zero. Func_get_arg() will generate a warning if called from outside of a function definition.

If arg_num is greater than the number of arguments actually passed, a warning will be generated and func_get_arg() will return FALSE.

  1 
  2 <?php
  3 function foo() {
  4      $numargs = func_num_args();
  5      echo "Number of arguments: $numargs<br>\n";
  6      if ($numargs >= 2) {
  7          echo "Second argument is: " . func_get_arg (1) . "<br>\n";
  8      }
  9 } 
 10 
 11 foo (1, 2, 3);
 12 ?>
 13       

Func_get_arg() may be used in conjunction with func_num_args() and func_get_args() to allow user-defined functions to accept variable-length argument lists.

Note: This function was added in PHP 4.


User Contributed Notes: func_get_arg


ak@avatartech.com
21-Apr-2000 08:47
You may pass any number of extra parameters to a function, regardless of the prototyping. For example:
function printme($x) {
  print($x);
  print(func_get_arg(2));
}
printme("one ","two");
This prints "one two". In the above function, func_get_arg(1) will return nothing, because the first argument has already been shunted into a variable.


loren@smoothsale.com
18-May-2000 09:34
The above example will give you a warning and will fail, because the array of function variables is zero-based. There is no function argument with index 2 in that example. You should call func_num_args() before calling func_get_arg() so you don't have this problem.


 About Notes


Previous page
 exit
func_get_args 
Next page



Site Statistics


Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.