Preg_replace_callback_array() function in PHP 7 represents a regular expression and replaces the use of callbacks. This function returns a string or an array of strings to match a set of regular expressions and replaces them using a callback function.Syntaxpreg_replace_callback_array(patterns, input, limit, count)Parameter Values:pattern − It requires an associate array to associate the regular expression patterns to callback functions.input/subject −It requires an array of strings to perform replacements.limit −It is optional. -1 is used for default, which means it is unlimited. It sets a limit to how many replacements can be done in each string.count −It is also optional like the ... Read More
The concept of generator is not new to PHP 7, because it was available in the earlier versions too. With generators, implementation becomes easy without the overhead of implementing a class that implements the iterator interface. With the help of a generator, we can write foreach code without using an array in memory. It also helps to eliminate the “exceed memory limit errors”.With the help of generator delegation in PHP 7, we can delegate to another generator automatically. It also allows arrays and objects that implement the traversable interface.Generator delegation Example 1Live Demo PHP 7 : Tutorialpoint ... Read More
In the previous versions of PHP, generator functions were not able to return expressions, but from the PHP 5.5, generator return expression is added in the existing one. By using generator return expressions, it is easy to use the return statement within a generator and, it also returns the value of the final expression.By using the generator return expression, we can only return the value of the expression but cannot return the reference. By using the new Generator::getReturn() method, we can fetch the value which can be used once the generator function has finished yielding the defined values.Using PHP 7 ... Read More
PHP 7 uses three different types of Group Use declarations −Non-mixed-use declarationsMixed-use declarationsCompound use declarationsNon-mixed-use declarations:Non-mixed-use declaration means we do not use the classes, functions, and constructs in a single statement. Or, we can say that when we declare classes, functions, and constants separately using a use statement. It is called Non-mixed group use declarations.Exampleuse Publishers\Packt\{ Book, Ebook, Video, Presentation }; use function Publishers\Packt\{ getBook, saveBook }; use const Publishers\Packt\{ COUNT, KEY };Mixed group use declarationsWhen we combine the PHP class, function and constants in a single-use statement, it is called a mixed group use declaration.Exampleuse Publishers\Packt\ { Book, ... Read More
In PHP 7, Group Use declaration is more readable and can be used to import classes, constants, and functions easily from the same namespace.Group Use declaration is used to import multiple structures easily from a namespace and cuts a good level of volubility in most cases. It is also useful to identify the multiple imported entities which belong to the same module.Example 1The following example shows the code before PHP 7 −Example 2The following example shows the code for PHP7 or PHP 7+use com\India\{ClassX, ClassY, ClassZ as Z}; use function com\India\{fn_x, fn_y, fn_z}; use const com\India\{ConstX, ConstY, ConstZ};ExplanationIn Example 1, ... Read More
When it is required to remove duplicates from a circular linked list, a 'Node' class needs to be created. In this class, there are two attributes, the data that is present in the node, and the access to the next node of the linked list.In a circular linked list, the head and the rear are adjacent to each other. They are connected to form a circle, and don't have 'NULL' value in the last node.Another class needs to be created that would have an initialization function, and the head of the node would be initialized to 'None'. Multiple methods are defined ... Read More
When it is required to insert a new node at the middle of the circular linked list, a 'Node' class needs to be created. In this class, there are two attributes, the data that is present in the node, and the access to the next node of the linked list.In a circular linked list, the head and the rear are adjacent to each other. They are connected to form a circle, and don't have 'NULL' value in the last node.Another class needs to be created that would have an initialization function, and the head of the node would be initialized ... Read More
When it is required to insert a new node at the end of the circular linked list, a 'Node' class needs to be created. In this class, there are two attributes, the data that is present in the node, and the access to the next node of the linked list.In a circular linked list, the head and the rear are adjacent to each other. They are connected to form a circle, and don't have 'NULL' value in the last node.Another class needs to be created that would have an initialization function, and the head of the node would be initialized ... Read More
When it is required to insert a new node at the beginning of a circular linked list, a 'Node' class needs to be created. In this class, there are two attributes, the data that is present in the node, and the access to the next node of the linked list.In a circular linked list, the head and the rear are adjacent to each other. They are connected to form a circle, and don't have 'NULL' value in the last node.Another class needs to be created that would have an initialization function, and the head of the node would be initialized ... Read More
When it is required to find the maximum and minimum node values from a circular linked list, a 'Node' class needs to be created. In this class, there are two attributes, the data that is present in the node, and the access to the next node of the linked list.In a circular linked list, the head and the rear are adjacent to each other. They are connected to form a circle, and don't have 'NULL' value in the last node.Another class needs to be created that would have an initialization function, and the head of the node would be initialized ... Read More