This was for an assignment. I had to write a function to compare two roman numerals. This had to return true only if the second number was larger than the first and had to be done without converting the letters into integers. Also prefix subtraction didn't apply so all the letters came in descending order.Here is what I came up with:<?phpfunction x_smaller_than_y($x_num,$y_num) {//Create array with ordered list of roman numerals. $evaluation= array(M,D,C,L,X,V,I);//Splits submitted numbers into arrays$x_num_arr = str_split($x_num);$y_num_arr = str_split($y_num);//Loops through each roman numeral in the given listfor ($evaluate = 0; $evaluate<7;$evaluate++)  {       //For every letter in the numerals' list loops through      //every letter in the given numbers looking for a match.     $counter = 0;     while ($counter < ((strlen($x_num)))&& $counter < ((strlen($y_num))))       {       //If in any specific position x=y, it simply ignores it and moves forward.       if ($x_num_arr[$counter]==$y_num_arr[$counter])           {$counter++;}       //If in any given position the letter in Y is higher in the list than         //the letter in X then Y is larger than X and the function is true.        //break ends the while loop and $evaluate=8 ends the for loop.       elseif(($x_num_arr[$counter]!=$evaluation[$evaluate])&&($y_num_arr[$counter]==$evaluation[$evaluate]))           {return true;            $evaluate=8;            break;}       //Same as above but this time the letter in X is before the letter        //in Y so the function is false.       elseif(($x_num_arr[$counter]==$evaluation[$evaluate])&&( $y_num_arr[$counter]!=$evaluation[$evaluate]))           {return false;            $evaluate=8;            break;}           //If none of the above cases apply simply move to the next letter.       else {$counter++;}        }    }//Since the number of iterations in the while loop is determined by the //shorter number there can still be a case in which 2 numbers are exactly //the same up to a point but one is simply longer than the other, //eg. MXVI and MXVII.//When this happens the for loop will have run through its natural //course, $evaluate will be equal to 7, and the code below will determine //the larger number by looking at their lenght. if ($evaluate<8&&(strlen($x_num) < strlen($y_num))){return true;}elseif ($evaluate<8&&(strlen($x_num) > strlen($y_num))){return false;}}How could have I made it better?
PHP function to compare two Roman numerals
php;algorithm;homework