Skip to content

Instantly share code, notes, and snippets.

@loganlinn
Last active December 19, 2015 05:19
Show Gist options
  • Save loganlinn/5902991 to your computer and use it in GitHub Desktop.
Save loganlinn/5902991 to your computer and use it in GitHub Desktop.
What do you expect would be output by this script?
<?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);
}
@loganlinn
Copy link
Author

@loganlinn
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment