Home > Article > Backend Development > How to remove the first element from php array
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. .
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');
Format and output the original content of the array, example:
echo '<pre class="brush:php;toolbar:false">'; print_r($arr); echo '<pre class="brush:php;toolbar:false">';
Save the above file on the screen Preview the original array content
Use array_shift() to delete the first element in the array, example:
echo array_shift($arr);
Save the above content and preview it on the screen again. The deleted element value will be printed on the screen.
Format the output again after the first element is deleted. , the data in the array
Save the above content and preview the final effect
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!