Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: userc865b
Added: Jan 26, 2018 8:29 AM
Modified: Jan 30, 2018 4:26 PM
Views: 20
Tags: php
gets function arguments as array makes it generic. This also works in constuctor!!! very useful!
get constructor arguments as array
  1. <?php
  2. function foo()
  3. {
  4.     $numargs = func_num_args();
  5.     echo "Anzahl der Argumente: $numargs<br />\n";
  6.     if ($numargs >= 2) {
  7.         echo "Das zweite Argument ist: " . func_get_arg(1) . "<br />\n"; // u can use this also in __construct() function!
  8.     }
  9.     $arg_list = func_get_args();
  10.     for ($i = 0; $i < $numargs; $i++) {
  11.         echo "Argument $i ist: " . $arg_list[$i] . "<br />\n";
  12.     }
  13. }
  14.  
  15. foo(1, 2, 3);
  16. ?>