
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1060 Articles for PHP

480 Views
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

388 Views
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

256 Views
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

914 Views
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

5K+ Views
In this post, we will understand the differences between 'for' and 'foreach' loops in PHP −The 'for' loopIt 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 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 execute them one at a time without running the conditional statement at the beginning of the loop's condition.Condition: ... Read More

8K+ Views
JavaScript and PHP are two of the most widely used and flexible computer languages that are used for building websites.PHP is currently the most widely used scripting language for server-side development, whereas JavaScript is a client-side scripting language. PHP is responsible for handling things on the server side, whereas JavaScript is responsible for handling things on the client side of the browser.Since PHP is derived from the C programming language, it is quite simple to learn for anyone who already possesses a solid foundation in C. Although both are used on websites in order to enhance their functionality, one of ... Read More

2K+ Views
To push values into an associative array, use the brackets [] []. At first create an associative array −$details= array ( 'id' => '101', 'name' => 'John Smith', 'countryName' => 'US' );The PHP code is as follows to insert values −Example Live Demo OutputArray ( [studentDetails] => Array ( [0] => Array ( [id] => 101 [name] => John Smith [countryName] => US ) ) )

846 Views
Let’s say the following is our string including hyphen and numbers as well −"John-45-98-78-7898906756"To extract numbers after – i.e. hyphen, use the concept of explode() with parameters - and $yourVariableName.The PHP code is as follows −Example Live Demo Output7898906756