PHP Roman Numbers convert

Roman Numbers convert

<?php
  function roman($num) {
    $chars = array("I", "V", "X", "L", "C", "D", "M");
    $str = strval($num);

    $len = strlen($str);
    $result = "";
    for ($i = 0; $i < $len; $i++) {
      $base = 2 * ($len - $i - 1);
      $chs = array($chars[$base], $chars[$base + 1], $chars[$base + 2]);
      $romanchars = array("",
        $chs[0],
        $chs[0] . $chs[0],
        $chs[0] . $chs[0] . $chs[0],
        $chs[0] . $chs[1],
        $chs[1],
        $chs[1] . $chs[0],
        $chs[1] . $chs[0] . $chs[0],
        $chs[1] . $chs[0] . $chs[0] . $chs[0],
        $chs[0] . $chs[2]);

      $result .= $romanchars[$str[$i]];
    }
    return $result;
  }

?>