Passing in multiple values into a function. <?php $person = "Robert"; function myGreeting($greeting,$person,$endComment){ echo $greeting . $person . "," . $endComment; } myGreeting("Hello ", $person, "nice to see you again."); ?> ////////////////////////////////////////////////////////////////////////////////////////////////////// Passing in math values, assigning the total to a variable, retuning the value to the function. Then assign the function to a variable. After that we check to see if the answer is a specif value by using a if statement. <?php function mySum($val1,$val2,$val3){ $sum = $val1 + $val2 + $val3; return $sum; } $myTotal = mySum(20, 20, 20); echo $myTotal; if($myTotal == 60){ echo "<br><br>Yes the answer is 60."; }else{ echo "<br><br>Nah nigga the answer is not 60."; } ?> ///////////////////////////////////////////////////////////////////////////////////////////////////////
Using deult values to surpress errors in function if all the parameter have not been assigned. <?php function paint($color="blue",$room="office."){ echo "I am going to use the color {$color} to paint my {$room}."; } paint("tope","bedroom"); ?> /////////////////////////////////////////////////////////////////////////////////////////////////////// Order of operation in a mathamatical problem. You process whats in double quotes first. <?php $var1 = 10; $var2 = 20; $result = (($var1 + 100) - $var2) * 5; echo $result += 5 - 20; ?> //////////////////////////////////////////////////////////////////////////////////////////////////////// Using variable within a echo string. Just add the variable within curley braces. <?php function aName($names){ echo "Hello {$names}, welcome back to the site."; } aName("Robert Atkinson"); ?> |