问题
I'm confused about the term Ordinal value of a character or a string in php documentation. Can somebody tell me what exactly an ordinal value is?
回答1:
One "character" in PHP is one byte. Note that this is misleading for multi-byte characters, in which one character (say "漢") is encoded in multiple bytes. Anyway though, a byte is 8 bits and can represent a number between 0 and 255. The ordinal value of a character byte is simply this numerical value.
ord('a') -> 97
Read http://kunststube.net/encoding if you need more background information about bytes/characters/encodings.
回答2:
Ordinal value is Nothing but the ASCII value of a character And as we know every character takes one byte i.e. 8 bits and every bit can have either 0 or 1 as the possible value so every bit can have 2 values thus 8 positions can have power(2,8) = 256 combinations and every combination resembles 1 character like
00000000 => Null(0)
00010000 => Space(32)
(65 - 91) in Ascii => a-z
(97 - 122) in Ascii => (A-Z)
and (48 - 57) in Ascii => (0 - 9)
other combinations are assigned to other special chacater.
PHP have an inbuilt Function ord('a') which takes character as an argument and returns its ascii value i.e. 65 in this case
回答3:
The Ordinal Value of a character is nothing but the numeric location of a character.
来源:https://stackoverflow.com/questions/19174563/what-is-an-ordinal-value-of-a-string