Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Urmila Samariya
Page 11 of 11
Number comparisons in PHP 8
PHP 8 introduced significant changes to number comparisons, making them more consistent and predictable. When comparing values, PHP 8 uses number comparison for numeric types, but converts numbers to strings for string comparisons, following stricter rules. String Categories Strings can be categorized in three ways − Numeric string − Contains only numeric characters. Example − "1234" or "1.24e1". Leading-numeric string − Starts with numeric characters followed by non-numeric characters. Example − "12xyz" or "123 " Non-numeric string − Cannot be interpreted as numeric. Example − "foo" or "abc123" PHP 7 vs PHP 8 Comparison ...
Read MoreUniform variable syntax in PHP 7
In older versions of PHP, variable syntax was inconsistent and could be confusing. For example, expressions like ${$first['name']} created ambiguity in parsing order. PHP 7 introduced Uniform Variable Syntax to resolve these inconsistencies by enforcing left-to-right evaluation. The uniform variable syntax evaluates variables from left to right and requires proper use of curly brackets for clarity − echo ${$first['name']}; This syntax allows new combinations of operators but may break backward compatibility in expressions that relied on older evaluation patterns. Function Expression Example With uniform variable syntax, you can immediately invoke function expressions − ...
Read MoreUnicode codepoint escape syntax in PHP 7
PHP 7 introduced Unicode codepoint escape syntax, allowing you to write Unicode characters directly in double-quoted strings using the \u{xxx} format. This syntax accepts hexadecimal codepoints of varying lengths (2, 4, 6, or more digits) and produces UTF-8 character output. Syntax The Unicode escape syntax follows this pattern − "\u{hexadecimal_codepoint}" Leading zeros are optional, so \u{aaa} and \u{0000aaa} produce the same result. Basic Example Here's how to use Unicode codepoints in PHP 7 − પપ香 Right-to-Left Text Example Some languages like Hebrew and ...
Read MoreDisplay array structure and values in PHP 7
An array in PHP is a data structure that can store multiple elements under a single variable. To display array structure and values in PHP, we can use print_r() or var_dump() functions to show array contents in human-readable format. Using print_r() The print_r() function displays variable information in a human-readable format, showing array keys and elements clearly − Array ( [x] => Dept [y] => Employee [z] => Array ( ...
Read MorePreg_replace_callback_array() in PHP 7
The preg_replace_callback_array() function in PHP 7 performs pattern matching and replacement using multiple regular expressions with their corresponding callback functions. This function allows you to apply different callbacks for different patterns in a single operation. Syntax preg_replace_callback_array(patterns, subject, limit, count, flags) Parameters patterns − An associative array mapping regular expression patterns to callback functions. subject − The input string or array of strings to perform replacements on. limit − Optional. Maximum number of replacements for each pattern. Default is -1 (unlimited). count − Optional. Variable that will contain the number of replacements performed. ...
Read MoreGenerator Return Expressions in PHP 7
In PHP 7, generator functions can now return expressions using the return statement. This enhancement allows generators to yield values during iteration and then return a final value when the generator completes execution. Key Features Generator return expressions in PHP 7 provide the following capabilities − Return a final value from a generator function after all yields are completed Retrieve the returned value using the Generator::getReturn() method Only expression values can be returned, not references The return value is accessible once the generator has finished yielding all values Basic Example Here's a simple ...
Read MoreGroup Use declarations in PHP 7
In PHP 7, Group Use declarations provide a more readable way to import classes, constants, and functions from the same namespace. This feature reduces code verbosity and makes it easier to identify multiple imported entities that belong to the same module. Group Use declarations allow you to import multiple structures from a namespace in a single statement, eliminating redundant code and improving maintainability. Syntax The basic syntax for Group Use declarations is − use namespace\{ClassA, ClassB, ClassC}; use function namespace\{function1, function2, function3}; use const namespace\{CONST1, CONST2, CONST3}; Before PHP 7 (Traditional Approach) ...
Read MorePHP – Return an array of all supported encodings with mb_list_encodings()
The mb_list_encodings() function in PHP is used to return an array of all supported encodings. This function is supported in PHP 5 or higher version.Syntaxarray mb_list_encodings()Parametersmb_list_encodings() takes no parameters.Return ValuesThis function returns a numerically indexed array.Errors/Exceptionsmb_list_encodings() does not produce any errors.Examplemb_list_encodings() does not produce any errors.OutputIt will produce the following output −array(87) { [0]=> string(4) "pass" [1]=> string(4) "auto" [2]=> string(5) "wchar" [3]=> string(7) "byte2be" [4]=> string(7) "byte2le" [5]=> string(7) "byte4be" [6]=> string(7) "byte4le" [7]=> string(6) "BASE64" [8]=> string(8) "UUENCODE" [9]=> string(13) ...
Read More