Server Side Programming Articles

Page 1012 of 2109

Unicode codepoint escape syntax in PHP 7

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 769 Views

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 More

Display array structure and values in PHP 7

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 14K+ Views

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 More

Preg_replace_callback_array() in PHP 7

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 337 Views

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 More

Generator Return Expressions in PHP 7

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 452 Views

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 More

Group Use declarations in PHP 7

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 1K+ Views

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 More

Difference Between For and Foreach in PHP

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 5K+ Views

In this post, we will understand the differences between for and foreach loops in PHP − The 'for' Loop It is an iterative loop that repeats a set of code till a specified condition is reached. It is used to execute a set of code for a specific number of times. Here, the number of times is controlled by the iterator variable. Syntax for( initialization; condition; increment/decrement ) { // code to iterate and execute } Initialization: It is used to initialize the iterator variables. It also helps ...

Read More

Extract numbers after the last hyphen in PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 925 Views

In PHP, you can extract numbers after the last hyphen in a string using various methods. The most straightforward approach is using the explode() function to split the string and access the last element. Using explode() with Array Index Split the string by hyphens and access the last element using its index ? 7898906756 Using array_pop() Method A more elegant approach using array_pop() to get the last element ? 7898906756 Using end() Function Another method using end() to get the ...

Read More

PHP How to cast variable to array?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 700 Views

To cast a variable to array in PHP, use the array casting syntax. This is useful when you need to ensure a variable is always an array type, regardless of its original data type. Syntax The basic syntax for casting to array is ? $yourNewVariableName = (array)$yourVariableName; Example with Array Variable When casting an existing array, it remains unchanged ? Array ( [0] => Mike [1] => Sam [2] => David ) Example ...

Read More

PHP How to display array values with text "even" to be displayed for even index values

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 190 Views

In PHP, you can display array values with the text "even" for even index positions using a for loop with conditional logic. This technique checks if an index is divisible by 2 and assigns "Even" text or the actual value accordingly. Example The following example creates an array and displays "Even" for even index values ? Even 1 Even 3 Even How It Works The code uses the modulo operator (%) to check if an index is even. When $counter % 2 == 0 is true (for indices 0, ...

Read More

How to display array values with do while or for statement in my PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 283 Views

In PHP, you can display array values using loop structures like do-while and for statements. These loops provide different approaches to iterate through array elements and display them. Syntax The basic syntax for a do-while loop is − do { // statements } while (condition); The basic syntax for a for loop is − for (initialization; condition; increment) { // statements } Using do-while Loop The do-while loop executes the code block at least once before checking the condition ? ...

Read More
Showing 10111–10120 of 21,090 articles
Advertisements