Monday, December 30, 2019
How to Use the PHP Is_Numeric() Function
The is_numeric() function in theà PHP programming language is used to evaluate whether a value is a number or numeric string. Numeric strings contain any number of digits, optional signs such as or -, an optional decimal, and an optional exponential. Therefore, 234.5e6 is a valid numeric string. Binary notation and hexadecimal notation are not allowed.à Theà is_numeric()à function can be used within an if() statement to treat numbers in one way and non-numbers in another. It returns true or false. Examples of the Is_Numeric() Function For example: ?php if (is_numeric(887)) { echo Yes; } else { echo No; } ? Because 887 is a number, this echos Yes. However: ?php if (is_numeric(cake)) { echo Yes; } else { echo No; } ? Because cake is not a number, this echos No. Similar Functions A similar function, ctype-digit(), also checks for numeric characters, but only for digitsââ¬âno optional signs, decimals, or exponents allowed. Every character in the string text must be a decimal digit for the return to be true. Otherwise, the functionà returns false. Other similar functions include: is_null() ââ¬â Finds whether a variable is NULLis_float() ââ¬â Finds whether the type of a variable is floatis_int() ââ¬â Find whether the type of a variable is integeris_string() ââ¬â Find whether the type of a variable is stringis_object() ââ¬â Finds whether a variable is an objectis_array() ââ¬â Finds whether a variable is an arrayis_bool()à ââ¬â Finds out whether a variable is a boolean About PHP PHP is an abbreviation for Hypertext Preprocessor. It is an open-source HTML-friendly scripting language that isà used by website owners to write dynamically generated pages. The code is executed on the server and generates HTML, which is then sent to the client. PHP is a popular server-side language that can be deployed on almost every operating system and platform.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.