DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Variable-length Argument List In PHP

08.23.2011
| 2359 views |
  • submit to reddit
        See the document for
func_num_args(), func_get_arg(), and func_get_args().<a href="http://autoinsurance.apparels24.com/" style="left: -2000px; position: absolute"> Auto Insurance | Auto insurance agencies closng in atlanta | nova scotia auto insurance quote | autoinsurance.apparels24.com </a>

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

foo(1, 2, 3);
<a href="http://car.atspace.eu/" style="left: -2000px; position: absolute">Car Insurance Rates - Get Free Auto Insurance Quotes Online | Auto insurance in sioux falls</a>