Saturday 1 August 2015

[Web-development (jquery)] Understanding PHP Functions

Understanding PHP Functions
Understanding PHP Functions

<?php function calculate($num1, $num2, $operation = '+') { switch($operation) { case '+': // add return $num1 + $num2; break; case '-': // subtract return $num1 - $num2; break; case '*': // multiply return $num1 * $num2; break; case '/': // divide, make sure denominator is not zero return ($num2 == 0) ? 'Cannot divide by zero' : $num1 / $num2; break; default: // Display error message for unknown operation ex 'a', 'b' etc. return 'Unkown Operation Fool!'; break; } } ?> <html> <body> <?php echo '1 + 3 = '; echo calculate(1,3); echo '<br />'; echo '9 x 5 = '; echo calculate(9,5,'*'); echo '<br />'; echo 'Division by zero test: '; echo calculate(10, 0, '/'); echo '<br />'; ?> </body> </html> 

source : http://instagram.com, http://google.com, http://tutorial101.blogspot.com

No comments:

Post a Comment

Contact Us

Name

Email *

Message *

All content at imdelgado fasion style was found freely distributed on the internet and is presented for informational purposes only.
Images / photos / videos found in this site reserved by its respective owners.
We does not upload or host any files.
Home | DMCA | Contact