Skip to content

Instantly share code, notes, and snippets.

@smunchi
Created November 10, 2021 07:30
Show Gist options
  • Select an option

  • Save smunchi/a4f1ef89fe56b9d45b38f785a23ea748 to your computer and use it in GitHub Desktop.

Select an option

Save smunchi/a4f1ef89fe56b9d45b38f785a23ea748 to your computer and use it in GitHub Desktop.
integers to roman conversion
function integersToRomanNumeral($number)
{
$values = [1000, 500, 100, 50, 10, 5, 1];
$romanNumerals = ['M', 'D', 'C', 'L', 'X', 'V', 'I'];
$result = [];
for($i = 0; $i<count($values); $i++) {
while($number >= $values[$i]) {
$number = $number - $values[$i];
$result[] = $romanNumerals[$i];
}
}
return implode("", $result);
}
echo integersToRomanNumeral(50);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment