When you need to obtain the ASCII value of a character which of the following function you apply in PHP?
Reveal answer
Fill a bubble to check yourself
When you need to obtain the ASCII value of a character which of the following function you apply in PHP?
chr( );
asc( );
ord( );
val( );
The ord() function in PHP returns the ASCII value of a single character. It converts a character to its corresponding integer representation in the ASCII table. The chr() function does the reverse - it converts an ASCII value to its corresponding character. There is no asc() or val() function for this purpose in PHP. To get an ASCII value, you would use ord('A') which returns 65 for uppercase 'A'.
In PHP, ord() returns the ASCII (or byte) value of the first character of a string, which is exactly what's needed to convert a character to its numeric code point. chr() does the reverse — converting a numeric code back into a character — so it's a common but incorrect swap for this purpose.