Tutorial 19 – Functions
| In: 19. Functions | 11,273 views
Video Tutorial
Part 1
Part 2
Video Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | <?php //File Description: PHP Functions /* function theNameOfTheFunction () { execute this code } */ // Basic Function Example // Function that displays Hello function sayHello() { echo "Hello "; } sayHello(); // call the function echo "Robert <br>"; // Basic Function With 1 Parameter // Function that takes a number and multiples // it by 2 function multiplyByTwo($number) { $answer = $number * 2; echo "<b>$answer</b><br>"; } echo "3 * 2 = "; multiplyByTwo(3); // call our function // Basic Function With 2 Parameters // Function that takes 2 numbers and adds // them together function sumOfTwoNumbers($num1, $num2) { $sum = $num1 + $num2; echo "<b>$sum</b><br>"; } echo "100 + 100 = "; sumOfTwoNumbers(100, 100); // call our function // Basic Function Returning A Value // Function that returns the sum of 2 numbers function sumOfTwoNumbers2($num1, $num2) { $sum = $num1 + $num2; return $sum; } echo "300 + 100 = "; $result = sumOfTwoNumbers2(300,100); echo "$result <br>"; // Basic Function Pass Variable by Reference // Function that resets the value of a variable function resetToZero(&$variable) { $variable = 0; } $x = 900; resetToZero($x); // reset x to 0 echo $x; // Built In PHP Function Example // Function that returns the number of days // for a certain month for a specific year $days = cal_days_in_month(CAL_GREGORIAN,2,2011); echo "<br> In Feb. of 2011 there was $days days."; ?> |
Built In PHP Functions: Click Here
4 Responses to Tutorial 19 – Functions
dushPHP
January 19th, 2015 at 7:24 pm
Robert Smith
January 24th, 2015 at 7:35 pm
gomexcarlos
March 7th, 2016 at 11:09 pm
mhmd
August 29th, 2016 at 8:54 am