How to remove first element from an array in PHP?29 Aug 2024 | 2 min read To remove the first element or value from an array, array_shift() function is used. This function also returns the removed element of the array and returns NULL if the array is empty. After removing first element, the key of the other elements is modified, and again array is numbered from beginning, only if the keys are numerical. It is an inbuilt array function of PHP, which shifts an element from the beginning of the array. Returns ValueThe array_shift() function, which is used to remove the first element from an array, returns the removed element. It also returns NULL, if the array is empty. For example: Using string elementsOutput An element "Blue" is removed from the first position in the given array, and updated list is displayed in the given output. Arraylist: Array ( [0] => Blue [1] => Red [2] => Black [3] => Green [4] => Gray [5] => White ) Removed element from array is: Blue Updated arraylist: Array ( [0] => Red [1] => Black [2] => Green [3] => Gray [4] => White ) Example: Using numeric keys Output Removed element: Carom Array ( [0] => Chess [1] => Ludo ) Example: Using numeric values Output An element Removed array element is: 25 Update array is: Array ( [0] => 12 [1] => 65 2] => 37 [3] => 95 [4] => 38 [5] => 12 ) |
PHP An HTML form contains various input fields such as a text box, checkbox, radio buttons, submit button, checklist, etc. These input fields need to be validated, which ensures that the user has entered information in all the required fields and also validates that the...
7 min read
In this article, we will learn how to get selected option values in PHP. In this, we will learn some basic PHP concepts, and after that, we learn this concept with the help of various examples. What do you mean by PHP? PHP is a widely used, open-source...
10 min read
The checks the probability of the given input GMP number to being prime. This function determines if the given GMP number is a prime or not. This function is used for large and complicated numerical values. Syntax The given syntax shows the GMP function for identifying the...
3 min read
Introduction to PHP is an open-source general-purpose scripting language, which is widely used for creating dynamic and interactive web pages. PHP can access a large range of relational database management systems such as MYSQL, SQLite, and PostgreSQL. The PHP 5.1 version offered a new database connection...
5 min read
PHP has a built-in function called gmp_cmp() that is used to compare two GMP numbers. Syntax The following syntax shows a clear bit function using GMP numbers. gmp_cmp($number1, $number2); Parameter The two GMP numbers such as $number1 and $number2 are required parameters for this function. In PHP versions 5.6 and later, the...
2 min read
The Imagick::charcoalImage() method is a PHP built-in function for simulating a charcoal drawing of an image. This function will create a charcoal image of the parameter image which is passed as an input, the image which we will pass as an input to this function the...
4 min read
PHP Imagecreate( ) Function Image create ( ) function is another inbuilt PHP function mainly used to create a new image. The function returns the given image in a specific size. We need to define the width and height of the required image. Instead of the image...
4 min read
Not only in PHP, but also in other programming languages, appending or adding an element to an array is a frequent approach. In PHP, however, there are a few techniques for adding elements to an array. These approaches differ depending on their intended usage. You can...
3 min read
In this section, we will learn the use of CPanel to create a custom php.ini file. The php.ini file is the most important configure file. In this file, we will declare our PHP settings changes. When we use php to run any application, it will be...
2 min read
MVC is a software architectural pattern for implementing user interfaces on computers. It divides a given application into three interconnected parts. This is done to separate internal representations of information from the ways information is presented to, and accepted from the user. MVC stands for "Model view...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India