[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 06-23-2006, 11:16 PM   #1 (permalink)
NamePros Member
 
Join Date: Mar 2006
Location: new jersey
Posts: 90
0.00 NP$ (Donate)

mistik is an unknown quantity at this point


PHP NEWB Question

I am havbing trouble understanding the concepts of function arugments and multiple arguments

Could someone explain the meaning of them for me please. Are they variables that function can only use? Or are they placeholders for when the function is excuted? I am very new to php.(as-if you cant tell.)
mistik is offline  
Old 06-23-2006, 11:31 PM   #2 (permalink)
NamePros Regular
 
Join Date: Feb 2006
Posts: 581
192.30 NP$ (Donate)

psalzmann is just really nicepsalzmann is just really nicepsalzmann is just really nicepsalzmann is just really nice


A basic example of a function that accepts 2 arguments:

PHP Code:
function my_math_function($number1, $number2)
{
      
$result = ($number1+$number2);
      return
$result;
}
Is your basic function to add 2 numbers together so you don't have to continously re-write the same addition function.

To use this, you would call it like this:

echo my_math_function(5, 5);

should ouput:

10

Regards,
Peter
__________________
ILance - Enterprise Auction Software : As Seen on CNN & Fox News - View Online Demo - PHP/MySQL - SEO ready | 100% Customizable!
psalzmann is offline  
Old 06-23-2006, 11:55 PM   #3 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services

 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
www.php.net/manual/en/language.functions.php
__________________
Eric is offline  
Old 06-23-2006, 11:56 PM   #4 (permalink)
NamePros Member
 
Join Date: Mar 2006
Location: new jersey
Posts: 90
0.00 NP$ (Donate)

mistik is an unknown quantity at this point


so then the agurments is like a placeholder then?
mistik is offline  
Old 06-24-2006, 12:06 AM   #5 (permalink)
NamePros Regular
 
Join Date: Feb 2006
Posts: 581
192.30 NP$ (Donate)

psalzmann is just really nicepsalzmann is just really nicepsalzmann is just really nicepsalzmann is just really nice


Quote:
Originally Posted by mistik
so then the agurments is like a placeholder then?
Yes, basically you can have as many arguments as you desire.

Also, keep in mind you can have dummy arguments in place without having to use them:

Check it out:

function add_something($arg1, $arg2, $arg3 = '', $arg4 = '')
{
...
}

With that above, you are telling this function that you will always use argument $arg1 and $arg2 but $arg3 and $arg4 may or may not be used (notice how I assigned dummy blank values beside them?

Here is a perfect example:

PHP Code:
function do_math($arg1, $arg2, $arg3 = '', $arg4 = '')
{
    if (isset(
$arg3) AND $arg3 == 'subtract')
    {
        
$result = ($arg1-$arg2);
    }
    else if (isset(
$arg3) AND $arg3 == 'add')
    {
        
$result = ($arg1+$arg2);
    }
    return
$result;
}
$result = do_math(5, 2, 'subtract');
or you may need this:
$result = do_math(5, 2, 'add');
__________________
ILance - Enterprise Auction Software : As Seen on CNN & Fox News - View Online Demo - PHP/MySQL - SEO ready | 100% Customizable!
psalzmann is offline  
Old 06-24-2006, 12:10 AM   #6 (permalink)
NamePros Member
 
Join Date: Mar 2006
Location: new jersey
Posts: 90
0.00 NP$ (Donate)

mistik is an unknown quantity at this point


ok im getting it i thought they were like variables holding data when really they are just there to refer back to in the function, thanks for clearing that up for me psalzmann
mistik is offline  
Closed Thread


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

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


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 12:33 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85