Home>Article>Backend Development> How to remove the first element from php array

How to remove the first element from php array

藏色散人
藏色散人 Original
2021-05-10 10:53:21 2572browse

How to remove the first element from a php array: First create a PHP file and define an array; then use the "echo array_shift($arr);" statement to delete the first element in the array. .

How to remove the first element from php array

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer

Create a PHP file and define an array, example :

$arr = array('apple', 'orange', 'banana', 'watermelon');

How to remove the first element from php array

Format and output the original content of the array, example:

echo '
'; print_r($arr); echo '
';

How to remove the first element from php array

Save the above file on the screen Preview the original array content

How to remove the first element from php array

Use array_shift() to delete the first element in the array, example:

echo array_shift($arr);

How to remove the first element from php array

Save the above content and preview it on the screen again. The deleted element value will be printed on the screen.

How to remove the first element from php array

Format the output again after the first element is deleted. , the data in the array

How to remove the first element from php array

Save the above content and preview the final effect

How to remove the first element from php array

Recommended study: "PHP video tutorial

The above is the detailed content of How to remove the first element from php array. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn