About us Privacy Disclaimer Contact us
FAQ Help Advertising Feedback
Home Sitemap Search Donate us

  Home > Computer & I'net > Functions - Arguments...

   Browse by title articles:
   What is hot:

Character Classes

Matching/Replacing

Functions - Intro

Functions - Arguments

Functions - Return Values

Include

Understanding Relational Databases: Introduction
Email - Multiple Recipients
Six Golden Rules of a Pay Per Click Marketing Campaign
Disk Stripe Windows XP
Prev articles123456789 10 1112Next articles



Functions - Arguments


Computer & I'net articlesFunctions - Arguments

by David Stanley    



Arguments. No it's not about two functions getting into a fight. An argument is information being passed from the coding into the function.

The parentheses in the function area will hold varables. These variables will catch the information being sent into the function. Each variable is seperated by a comma.

function function_name ($variable1,$variable2,$variable3) {
    some PHP commands;
    some PHP commands;
}

When the function is called from the coding area, it will have values in its parentheses area which will be passed into the function. The values can be a variable (which holds a value) or a quoted value itself.

function_name ($variablename,"MyName",$anothervariable);

The information passed into the function goes in from left to right.
The value of $variablename will be passed into $variable1.
The value of "MyName" will be passed into $variable2.
And the value of $anothervariable will be passed into $varaible3.

So what happens if the function variable name is the same as the passed variable name but in a different order?

function function_name ($variable1,$variable2,$special) {
    some PHP commands;
    some PHP commands;
}

function_name ($special,"MyName",$anothervariable);

The value of $special from the coding will be passed into $variable1.
The value of "MyName" will be passed into $variable2.
And the value of $anothervariable will be passed into $special of the function.

What happened? Why didn't the two variable names match up with eachother? The function variables are just temporary storage spots which will be used inside the function only. They don't care about "outside" variable names. They just gather information from left to right and do their function commands.

Example :
<?php
function print_it_out($first_part,$second_part,$third_part){
    echo "$first_part $second_part $third_part";
}

$part3 = "HTMlite site.";
$part1 = "Welcome";
$part2 = "to the";

print_it_out($part1,$part2,$part3);
?>

Results :
Welcome to the HTMlite site.

What you may want to do however is keep the arguments matching with each other. Have the ones in the calling command show the same names as the arguments in the function command. This way there may be less confusion dealing with two variable names doing the one job.

<?php
function print_it_out($first_part,$second_part,$third_part){
    echo "$first_part $second_part $third_part";
}

$third_part = "HTMlite site.";
$first_part = "Welcome";
$second_part = "to the";

print_it_out($first_part,$second_part,$third_part);
?>




-----------------
Article by David Stanley. Visit his site http://www.htmlite.com. Reprinted with permission.





Credit card




  Disclaimer | Privacy | Terms of useCopyright © 2004 Nice2know.com