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

How to remove the first element in php

藏色散人
藏色散人Original
2021-02-20 09:28:321981browse

php移除第一个元素的方法:首先创建一个PHP示例文件;然后定义一个数组;最后通过“array_shift()”函数加while循环不断移除数组的第一个元素即可。

How to remove the first element in php

本文操作环境:windows7系统、PHP7.1版,DELL G3电脑

php通过array_shift()函数移除数组第一个元素的方法

下面的代码通过array_shift()函数加while循环不断移除数组的第一个元素,直到数组为空

<?php
$alpha = array("a", "b", "c");
while ( count( $alpha ) ) {
 $val = array_shift( $alpha);
 print "$val<br />";
 print "there are ".count( $alpha )." elements in \$alpha <br />";
}
?>

【推荐学习:《PHP视频教程》】

The above is the detailed content of How to remove the first element 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