Current location: Hot Scripts Forums » Programming Languages » PHP » optional arguments


optional arguments

Reply
  #1 (permalink)  
Old 08-08-04, 01:51 PM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
optional arguments

hi.. i was wondering how to make optional arguments in functions..
i have a function that needs 3 arguments, say page, pagelimit, table.. but then in some cases i need it to take 2 more: wherecol, whereval..

call and function:
PHP Code:

#call nr.1

echo pagelinks($page$pagelimit["$subject"], $subject); 
# results in warning: arg 4 and 5 missing

#call nr.2
echo pagelinks($page$pagelimit["$subject"], $subject"fid"$_GET['fid']);
# works fine

function pagelinks($page$pagelimit$table$wcol$wval
ideas??

thanks
Wille
Reply With Quote
  #2 (permalink)  
Old 08-08-04, 02:13 PM
xml xml is offline
New Member
 
Join Date: Jul 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Code:
function pagelinks ($page, $pagelimit, $table, $wcol, $wval) {
  if ($page && $pagelimit && $table && $wcol && $wval) {
    'DO PROCESSING WITH ALL ARGUEMENTS
  }

  elseif ($page && $pagelimit && $table && !$wcol && !$wval) {
    'DO PROCESSING WITH ONLY $page, $pagelimit and $table ARGUEMENTS
  }
}
Hope this helps.
__________________
XML training -- XML tutorial
Reply With Quote
  #3 (permalink)  
Old 08-08-04, 08:13 PM
mikaelf mikaelf is offline
Wannabe Coder
 
Join Date: Jun 2004
Location: php[dot]net
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
only by assigning optional arguments with empty string, you'll able to control code flow in the the function.
eg:
PHP Code:

function pagelinks($page$pagelimit$table$wcol ''$wval  '') {

    if(
$wcol == '' && $wval == '')
     
//Control goes here
    
else
      
//Control for full arguments

Function call:
PHP Code:

#call nr.1 

echo pagelinks($page$pagelimit["$subject"], $subject); 
#call nr.2 
echo pagelinks($page$pagelimit["$subject"], $subject"fid"$_GET['fid']); 
Reply With Quote
  #4 (permalink)  
Old 08-09-04, 03:18 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by mikaelf
PHP Code:

function pagelinks($page$pagelimit$table$wcol ''$wval  '') {

    if(
$wcol == '' && $wval == '')
     
//Control goes here
    
else
      
//Control for full arguments

thats the way.. thanks
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ignored arguments NeerDeth PHP 1 04-13-04 10:52 PM


All times are GMT -5. The time now is 04:18 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.