Last active
December 19, 2015 05:19
-
-
Save loganlinn/5902991 to your computer and use it in GitHub Desktop.
What do you expect would be output by this script?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// some math operations | |
$instructions = array( | |
array('*', 2, 4), | |
array('/', 2, 4), | |
array('/', 2, 0), | |
); | |
// compute | |
foreach ($instructions as $instr) { | |
list($operation, $operand1, $operand2) = $instr; | |
switch ($operation) { | |
case '*': | |
$result = $operand1 * $operand2; | |
break; | |
case '/': | |
// prevent divide error | |
if ($operand2 == 0) { | |
echo "ERROR: Can't divide by 0\n"; | |
continue; | |
} | |
$result = $operand1 / $operand2; | |
break; | |
} | |
printf("RESULT: %d\n", $result); | |
} |
Author
loganlinn
commented
Jul 1, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment