How to remove the first element from php array

藏色散人
Release: 2023-03-09 14:56:02
Original
2641 people have browsed it

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');
Copy after login

How to remove the first element from php array

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

echo &#39;<pre class="brush:php;toolbar:false">&#39;;
print_r($arr);
echo &#39;<pre class="brush:php;toolbar:false">&#39;;
Copy after login

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template