![]() |
|
|||||||
| Register | FAQ | Members List | Downloads | Calendar | Today's Posts | Search | Webmaster Resources | Webmaster Blogs |
![]() UK Web Hosting |
![]() Website Hosting |
![]() UK One Way |
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
||||
|
We can easily create functions which can take variable number of arguments in php by using following three functions : func_num_args, func_get_arg and func_get_args. Following code will demonstrate how to do it :
Code:
<?php
function test_func()
{
echo 'No. of arguments passed ', func_num_args();
echo '<br />';
echo 'First argument passed : ', func_get_arg(0), '<br />';
echo 'List of all arguments passed : ';
print_r(func_get_args());
echo '<br /><br />';
}
test_func(1);
test_func(1, 2, 3, 4, 5, 6, 7);
?>
Quote:
|
|
||||
|
Now, lets deiscuss what each the three functions demonstrated in prvious code example do :
1) func_num_args function This function returns the total number of arguments passed to a user defined function. 2) func_get_args function This functions returns all the arguments passed to a user defined function in an array. 3) func_get_arg function This function takes a single argument which specifies the position of argument to return which was passed to the current user defined function. Function argument position is specified starting from 0. It returns the specified argument when successful or FALSE on error. |
|
|||||
|
Functions which take variable number of arguments in php are:-
int func_num_args ( ) mixed func_get_arg ( int arg_num) array func_get_args ( ) __________________________________________________ __________ Web Site Design |
![]() |
| Bookmarks |
| Webmaster Resources |
| • UK Web Hosting • UK WW SEO Tools • Free site submission • Web Directory |
| Advertisement |
![]() |
| Site Of the Month |
![]() Nominate site of the month |
|
|
| UK Webmaster World Forums - Internet marketing, web development, domain names, SEO contest and discussuons. |
| Subscribe to our feeds |