Home  >  Article  >  Backend Development  >  How to delete the first element of an array in php

How to delete the first element of an array in php

王林
王林Original
2020-08-26 14:08:172142browse

How to delete the first element of an array in php: You can use the php built-in function array_shift() to delete. This function is used to delete the first element in the array and returns the deleted element, or null if the array is empty.

How to delete the first element of an array in php

php built-in function array_shift() is used to delete the first element in the array and return the deleted element, or NULL if the array is empty.

(Recommended video tutorial: php video tutorial)

Function syntax:

array_shift(array)

(Recommended related tutorial: php graphic tutorial)

Code implementation:

<?php
$a=array("a"=>"yellow","b"=>"green","c"=>"blue");
echo array_shift($a);
print_r ($a);
?>

Run result:

yellow
Array ( [b] => green [c] => blue )

The above is the detailed content of How to delete the first element of an array in php. 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