PHP equivalent of Java Character.getNumericValue (char c)?

Is there a PHP equivalent of Java Character.getNumericValue(char c)?

+5
source share
3 answers

No. There is no baking in equivalents.

0
source

Use the function intval().

This will not handle letters or roman numbers the same way, but you can create your own method for this. However, it will handle standard numbers.

if (intval ("2") === 2)
  echo ("YAY!");
+2
source

ord

: , , getNumericValue. , - . , .

, , - , Unicode:

function getNumericValue($ch) {
  if (ctype_digit($ch))
    return ord($ch) - ord('0');
  if (ctype_upper($ch))
    return ord($ch) - ord('A') + 10;
  if (ctype_lower($ch))
    return ord($ch) - ord('a') + 10;
  return -1;
}
0