search
Homephp教程php手册分析PHP函数array_pop()的具体使用方式

分析PHP函数array_pop()的具体使用方式

Jun 13, 2016 am 11:06 AM
arrayphppopforintroduceusespecificfunctionanalyzeincreaseusarrayWayof

我们曾经为大家介绍过如何在数组的头尾增加元素的方法。下面我们就向大家介绍如何在数组的尾端删除数组元素的具体方法。首先,我们需要用到的函数是PHP函数array_pop()。

  • 函数array_pop()从数组的尾端删除一些元素: 
    <ol class="dp-xml">
    <li class="alt"><span><span><?   </span></span></li>
    <li class=""><span> </span></li>
    <li class="alt"><span>/* 首先我们建立一个数组 */   </span></li>
    <li class=""><span> </span></li>
    <li class="alt">
    <span>$</span><span class="attribute"><font color="#ff0000">fruitArray</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">array</font></span><span>("apple", "orange", "banana", "Peach", "pear");    </span>
    </li>
    <li class=""><span> </span></li>
    <li class="alt"><span>/* 使用array_pop()函数从数组的尾端删除一个元素 */   </span></li>
    <li class=""><span> </span></li>
    <li class="alt">
    <span>$</span><span class="attribute"><font color="#ff0000">popped</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">array_pop</font></span><span>($fruitArray);    </span>
    </li>
    <li class=""><span> </span></li>
    <li class="alt"><span>/* 现在我们把删除后的数组中所有元素的键(key)与值(value)都显示在网页上 */   </span></li>
    <li class=""><span> </span></li>
    <li class="alt"><span>while (list($key,$value) = each($fruitArray)) {   </span></li>
    <li class=""><span> </span></li>
    <li class="alt"><span>echo "$key : $value<br>";   </span></li>
    <li class=""><span> </span></li>
    <li class="alt"><span>}    </span></li>
    <li class=""><span> </span></li>
    <li class="alt"><span>echo "<br>最后,刚才被删除的元素的值会储存在 $popped 变量里面,它的值是:$popped";    </span></li>
    <li class=""><span> </span></li>
    <li class="alt"><span>?>   </span></li>
    </ol>

    显示结果如下: 

    0 : apple

    1 : orange

    2 : banana

    3 : Peach   

    最后,由PHP函数array_pop()删除的元素的值会储存在 $popped 变量里面,它的值是: pear 。 


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)