Skip to content

Instantly share code, notes, and snippets.

@RobDWaller
Last active February 27, 2018 10:07
Show Gist options
  • Save RobDWaller/2e01bf76ad4bc21ef7b4cc00fc378457 to your computer and use it in GitHub Desktop.
Save RobDWaller/2e01bf76ad4bc21ef7b4cc00fc378457 to your computer and use it in GitHub Desktop.
Dave's Code
<?php
function everyValueDivisibleByFive($array)
{
$newArray = [];
if (!count($array)) {
$result = 'error';
}
else {
foreach ($array as $row) {
if ($row % 5 != 0) {
$remainder = $row % 5;
if (5 - $remainder < 3) {
$addition = 5 - $remainder;
$newArray[] = $row + $addition;
}
else {
$newArray[] = $row - $remainder;
}
}
else {
$newArray[] = $row;
}
}
$result = $newArray;
}
return $result;
}
$result = everyValueDivisibleByFive([1, 7, 12, 18, 23, 34, 45]);
var_dump($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment