Tuesday, March 1, 2011

Create-new-function-PHP (Part 6)

Assalamu'alaikum and selamat sejahtera

So,now we will learn on the other alternative of the return.Before this,we must type "return" in order the function to return the value to any variable that come from the function.So,we just use one character only!to enable the return value.Here is the example:


<?PHP

$number1 = 120;
calculate_addition($number1);

print $number1;
 
function calculate_addition(&$number1){
$number2 = 10;


if ($number1 > 100) {
$number1=$number1+$number2;
}
 

else {
$number1= $number1-90;
}

}

?>

we just use "&" as the alternative of the return.Compare this code from previous post:

<?PHP
$number1 = 120;
$total = calculate_addition($number1);

print $total;
function calculate_addition($number1){
$number2 = 10;

if ($number1 > 100) {
$number1=$number1+$number2;
}

else {
$number1= $number1-90;
}

return $number1;
}

?>
 


N/NOTE:&!!!!!!

No comments:

Post a Comment