Introduction to the usage of PHP function array_shift() in deleting array elements_PHP tutorial

WBOY
Release: 2016-07-15 13:29:11
Original
1047 people have browsed it

In previous articles, we have described to you the specific usage of the function array_pop() to delete array elements at the end of the array. Today we introduce to you the method of deleting array elements at the beginning of the array. . Here we will use Next we will show you how the PHP function array_shift() deletes elements from the beginning of the array:

  1. <?
  2. /* 首先我们建立一个数组 */
  3. $fruitArray = array("apple", "orange", "banana", "Peach", "pear");
  4. /* 使用 array_shift()函数从数组的开头删除一个元素 */
  5. $shifted = array_shift($fruitArray);
  6. /* 现在我们把删除后的数组中所有元素的键(key)与值(value)都显示在网页上 */
  7. while (list($key,$value) = each($fruitArray)) {
  8. echo "$key : $value<br>";
  9. }
  10. echo "<br>最后,刚才被删除的元素的值会储存在 $shifted 变量里面,它的值是:
  11. $shifted";
  12. ?>
Copy after login

The result is as follows:

0 : orange

1 : banana

2 : Peach

3 : pear

Finally, the value of the element just deleted by the PHP function array_shift() It will be stored in the $shifted variable, and its value is: apple.


www.bkjia.com true http: //www.bkjia.com/PHPjc/446377.html TechArticle In our previous article, we have described to you the function array_pop() that deletes array elements at the end of the array. The specific usage, what we introduce to you today is to delete the number at the beginning of the array...
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!