Go Back   Webmaster Forums UK SEO SEM Webmaster Community Forum - UKWW > Web Design and Website Development > Programming > PHP Forum
Register FAQ Members List Downloads Calendar Today's Posts Webmaster Resources Webmaster Blogs
 
 

PHP Forum PHP related discussion, help, tips and tutorials.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-11-2008, 08:00 PM
dman_2007
Guest
 
Posts: n/a
Default Tip : Functions which take variable number of arguments in php

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); 
?>
When run the previous code will produce the following output :

Quote:
No. of arguments passed 1
First argument passed : 1
List of all arguments passed : Array ( [0] => 1 )

No. of arguments passed 7
First argument passed : 1
List of all arguments passed : Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 )
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 04-11-2008, 08:05 PM
dman_2007
Guest
 
Posts: n/a
Default

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.
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 05-29-2008, 07:14 AM
garima's Avatar
Junior Member
18 posts this year. the lights are on!
User is on their way up.
 
Join Date: May 2008
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Default

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
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
Reply

Bookmarks



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Webmaster Resources
UK WW SEO Tools
Find UK Hosts
 
The Forum Rules
Forum Rules - MUST READ
 
Site Of the Month
BizzFace
Nominate site of the month
 
Tag Cloud
affiliates ambitious asbestos cancer bid bidding directory bid directory bid directory list bid for position business clothes contest cricket writer delisted designer discount ecommerce email list email marketing finance forum free web hosting free website hosting global business directory google handbags huge email database internet and marketing iphone jewelry link submissions niche nokia n95 of mesothelioma paid blogging phones electronics pr7 directory replica samsung social bookmark startup sunglasses technology uk property writer wallets web web design web development website website for sale website promotion websites for sale wholesale yahoo backlink

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:23 PM.

UK Webmaster World Forums - Internet marketing, web development, domain names, SEO contest and discussuons.
Subscribe to our feeds   Subscribe to our feeds

Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0