NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page PHP NEWB Question

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

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 06-24-2006, 12:16 AM THREAD STARTER               #1 (permalink)
NamePros Member
Join Date: Mar 2006
Location: new jersey
Posts: 92
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-24-2006, 12:31 AM   #2 (permalink)
NamePros Regular
Join Date: Feb 2006
Posts: 528
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.
????: NamePros.com http://www.namepros.com/programming/210263-php-newb-question.html

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-24-2006, 12:55 AM   #3 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
www.php.net/manual/en/language.functions.php
Eric is offline  
Old 06-24-2006, 12:56 AM THREAD STARTER               #4 (permalink)
NamePros Member
Join Date: Mar 2006
Location: new jersey
Posts: 92
mistik is an unknown quantity at this point
 



so then the agurments is like a placeholder then?
mistik is offline  
Old 06-24-2006, 01:06 AM   #5 (permalink)
NamePros Regular
Join Date: Feb 2006
Posts: 528
psalzmann is just really nicepsalzmann is just really nicepsalzmann is just really nicepsalzmann is just really nice
 



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 '')
????: NamePros.com http://www.namepros.com/showthread.php?t=210263
{
    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, 01:10 AM THREAD STARTER               #6 (permalink)
NamePros Member
Join Date: Mar 2006
Location: new jersey
Posts: 92
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


Liquid Web Smart Servers  
All times are GMT -7. The time now is 05:48 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger