Tuesday, March 1, 2011

Create-new-function-PHP (Part 5)

Assalamu'alaikum and selamat sejahtera

So,for this post we will learn on how to get value from the function,before we already learn on how display the value of variable from the function.Ok,here is the code:


<?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;
}

?>

So for this post,let me explain the new word,"return".the concept is simple is that it is for assigning any variable from outside the function.In our case,we use $total to get the value from the return.So,we just got the value from the function.



 N/NOTE:the function,calculate_addition return the value ,and then $total are the variable that receive the value from the function.Proof:$total = calculate_addition($number1); .Any question?

No comments:

Post a Comment