фух 2 часа делал - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.

Name: фух 2 часа делал fullscreencopydownloadembedprint


Your result can be seen below.

Result of php executing





Full code of фух 2 часа делал.php

  1. <?php
  2. /**
  3.  * @param string $roman
  4.  * @return int
  5.  */
  6. function romanToNumber($roman){
  7.     $roman = strtoupper($roman);
  8.     $romans = [
  9.         'M' => 1000,
  10.         'CM' => 900,
  11.         'D' => 500,
  12.         'CD' => 400,
  13.         'C' => 100,
  14.         'XC' => 90,
  15.         'L' => 50,
  16.         'XL' => 40,
  17.         'X' => 10,
  18.         'IX' => 9,
  19.         'V' => 5,
  20.         'IV' => 4,
  21.         'I' => 1,
  22.     ];
  23.     $result = 0;
  24.     foreach ($romans as $key => $value) {
  25.         while (strpos($roman, $key) === 0) {
  26.             $result += $value;
  27.             $roman = substr($roman, strlen($key));
  28.         }
  29.     }
  30.     return $result;
  31. }
  32.  
  33. //uisng
  34. echo romanToNumber('mm'); // 2000
  35. echo romanToNumber('XIV'); // 14
  36.  
File Description
  • фух 2 часа делал
  • PHP Code
  • 21 Oct-2021
  • 696 Bytes
You can Share it: