unknown os platform
Free Beginner PHP Tutorials - Functions with arguments | Whats-online.info
whats-online-info

Free Beginner PHP Tutorials - Functions with arguments


Free
2016:09:23 / Science and Tutorials

PHP functions with arguments and no return value.





PHP - Functions with argument


On my previous post, I introduced what are PHP functions. For this tutorial, I will show how to pass information to functions as arguments and print the results. Then call our function on our program to execute.

Syntax

<?php functions AreaOfSquare($arg1,$arg2){ //print $arg1 and Arg2 }   AreaOfSquare($par1,$par2); ?>


Example
We will create a PHP function with two parameters ($length and height) to find the area of a square.

<?php      function  AreaOfSquare($width,$height){ $area=$width * $height; echo"The area of our square is ".$area; } //calling our function and pass two values      AreaOfSquare(20,15); ?>

output: The area of our square is 300;

Our function contains two arguments declared as $width and $height.
We pass 20 as the value of width and 15 as the value of height to our function. Our function will calculate the area and print it.

Then we call our function on our program to execute.












You may also like:


Leave a comment












Subscribe to get replies direct to your mailbox

Submit comment