} //if we get here, there was not a non-nine number, so return true return true; } /** * Converts a character to an integer * * @param char $someChar Character representation of a number * * @return int $someChar Integer representation of $someChar */ function CharToInt($someChar) { return (int) $someChar; } /** * Converts an integer to a character * * @param int $someInt Integer to be converted to a character * * @return char $someInt Character representation of $someInt */ function IntToChar($someInt) { return strval($someInt); } echo "Result (Single Nine): " . IncrementBigNum("129129") . "\n"; echo "Result (Consecutive Nines): " . IncrementBigNum("1299") . "\n"; echo "Result (No Nines): " . IncrementBigNum("122") . "\n"; echo "Result (All Nines): " . IncrementBigNum("999") . "\n";
//gets the index of the first non 9 value from the left in the number function GetFirstNonNine($bigNumString) { $lastIndex = strlen($bigNumString) - 1; for ($i = $lastIndex; $i >= 0; $i--) { if ($bigNumString[$i] != 9) { return $i; } } } //check if every number in the big number string is a nine function CheckForAllNines($bigNumString) { $lastIndex = strlen($bigNumString) - 1; for ($q = $lastIndex; $q >= 0; $q--) { if ($bigNumString[$q] != 9) { return false; } } return true; } function CharToInt($someChar) { return (int) $someChar; } function IntToChar($someInt) { return strval($someInt); } IncrementBigNum("129129");