Returnig Values from function:
From a function we can return values using optional return statement, in PHP we can return arrays, objects. With the help of the return statement the control moves back to the calling portion of the project. If we do not put any return statement then a NULL value is returned. A function can not have more than one return statement because whenever a return statement occurs rest of the statements are ignored by the parser. To know more about return statement please visit our site:
| www.roseindia.net/tutorial/php/phpbasics/tutorial/PHP-Return.html |
Example:
<?php
function
square($var){ return $var*$var;}
echo
"Square of 2 is: ".square(2);?>
Output:
Square of 2 is: 4Example:
<?php
function
fun(){ return array(0,1,2);}
list
($var1,$var2,$var3)=fun();echo
"Value of \$var1= ".$var1."<br/>";echo
"Value of \$var2= ".$var2."<br/>";echo
"Value of \$var3= ".$var3."<br/>";?>
Output:
Value of $var1= 0
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.