php:获取数组第一个值

php 获取数组 第一个值 <wbr><br><br><br> reset (PHP 3, PHP 4, PHP 5)<br> reset -- 将数组的内部指针指向第一个单元<br> 说明<br> mixed reset ( array &amp;array )<br> reset() 将 array 的内部指针倒回到第一个单元并返回第一个数组单元的值,如果数组为空则返回 FALSE。<br><br> 例 1. reset() 例子<br><div style="font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(240, 240, 240); font-family: Consolas, 'Lucida Console', 'Courier new'; color: rgb(32, 32, 32);"> <span style="color: rgb(160, 176, 192); font-style: italic;">01<wbr></wbr></span><span style="color: rgb(16, 96, 160);">&lt;?php</span><br><span style="color: rgb(160, 176, 192); font-style: italic;">02<wbr></wbr></span><span style="color: rgb(91, 54, 116); font-style: italic;">$array</span><span><wbr></wbr></span><span style="color: rgb(32, 32, 32);">=</span><span><wbr></wbr></span><span style="color: rgb(0, 112, 32); font-weight: bold;">array</span>(<span style="color: rgb(64, 112, 160);">'step one'</span><span style="color: rgb(32, 32, 32);">,</span><span><wbr></wbr></span><span style="color: rgb(64, 112, 160);">'step two'</span><span style="color: rgb(32, 32, 32);">,</span><span><wbr></wbr></span><span style="color: rgb(64, 112, 160);">'step three'</span><span style="color: rgb(32, 32, 32);">,</span><span><wbr></wbr></span><span style="color: rgb(64, 112, 160);">'step four'</span>);<br><span style="color: rgb(160, 176, 192); font-style: italic;">03<wbr></wbr></span><span style="color: rgb(160, 176, 192); font-style: italic;">// by default, the pointer is on the first element</span><br><span style="color: rgb(160, 176, 192); font-style: italic;">04<wbr></wbr></span><span style="color: rgb(0, 112, 32); font-weight: bold;">echo</span><span><wbr></wbr></span><span style="color: rgb(76, 143, 47); font-weight: bold;">current</span>(<span style="color: rgb(91, 54, 116); font-style: italic;">$array</span>)<span><wbr></wbr></span><span style="color: rgb(32, 32, 32);">.</span><span><wbr></wbr></span><span style="color: rgb(64, 112, 160);">"&lt;br /&gt;</span><span style="color: rgb(64, 112, 160);">\n</span><span style="color: rgb(64, 112, 160);">"</span>;<span><wbr></wbr></span><span style="color: rgb(160, 176, 192); font-style: italic;">// "step one"</span><br><span style="color: rgb(248, 16, 176);">05<wbr></wbr></span><span style="color: rgb(160, 176, 192); font-style: italic;">// skip two steps</span><br><span style="color: rgb(160, 176, 192); font-style: italic;">06<wbr></wbr></span><span style="color: rgb(76, 143, 47); font-weight: bold;">next</span>(<span style="color: rgb(91, 54, 116); font-style: italic;">$array</span>);<br><span style="color: rgb(160, 176, 192); font-style: italic;">07<wbr></wbr></span><span style="color: rgb(76, 143, 47); font-weight: bold;">next</span>(<span style="color: rgb(91, 54, 116); font-style: italic;">$array</span>);<br><span style="color: rgb(160, 176, 192); font-style: italic;">08<wbr></wbr></span><span style="color: rgb(0, 112, 32); font-weight: bold;">echo</span><span><wbr></wbr></span><span style="color: rgb(76, 143, 47); font-weight: bold;">current</span>(<span style="color: rgb(91, 54, 116); font-style: italic;">$array</span>)<span><wbr></wbr></span><span style="color: rgb(32, 32, 32);">.</span><span><wbr></wbr></span><span style="color: rgb(64, 112, 160);">"&lt;br /&gt;</span><span style="color: rgb(64, 112, 160);">\n</span><span style="color: rgb(64, 112, 160);">"</span>;<span><wbr></wbr></span><span style="color: rgb(160, 176, 192); font-style: italic;">// "step three"</span><br><span style="color: rgb(160, 176, 192); font-style: italic;">09<wbr></wbr></span><span style="color: rgb(160, 176, 192); font-style: italic;">// reset pointer, start again on step one</span><br><span style="color: rgb(248, 16, 176);">10<wbr></wbr></span><span style="color: rgb(76, 143, 47); font-weight: bold;">reset</span>(<span style="color: rgb(91, 54, 116); font-style: italic;">$array</span>);<br><span style="color: rgb(160, 176, 192); font-style: italic;">11<wbr></wbr></span><span style="color: rgb(0, 112, 32); font-weight: bold;">echo</span><span><wbr></wbr></span><span style="color: rgb(76, 143, 47); font-weight: bold;">current</span>(<span style="color: rgb(91, 54, 116); font-style: italic;">$array</span>)<span><wbr></wbr></span><span style="color: rgb(32, 32, 32);">.</span><span><wbr></wbr></span><span style="color: rgb(64, 112, 160);">"&lt;br /&gt;</span><span style="color: rgb(64, 112, 160);">\n</span><span style="color: rgb(64, 112, 160);">"</span>;<span><wbr></wbr></span><span style="color: rgb(160, 176, 192); font-style: italic;">// "step one"</span><br><span style="color: rgb(160, 176, 192); font-style: italic;">12<wbr></wbr></span><span style="color: rgb(16, 96, 160);">?&gt;</span> </div> <br><br><br> next(PHP 3, PHP 4, PHP 5)<br> next --<wbr> 将数组中的内部指针向前移动一位<br> 说明<br> mixed next ( array &amp;array )<br> 返回数组内部指针指向的下一个单元的值,或当没有更多单元时返回 FALSE。<br><br> next() 和 current() 的行为类似,只有一点区别,在返回值之前将内部指针向前移动一位。这意味着它返回的是下一个数组单元的值并将数组指针向前移动了一位。如果移动指针的结果是超出了数组单元的末端,则 next() 返回 FALSE。<br><br> 警告<br> 如果数组包含空的单元,或者单元的值是 0 则本函数碰到这些单元也返回 FALSE。要正确遍历可能含有空单元或者单元值为 0 的数组,参见 each() 函数。<br><br> 例 1. next() 及相关函数的用法示例<br><div style="font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(240, 240, 240); font-family: Consolas, 'Lucida Console', 'Courier new'; color: rgb(32, 32, 32);"> <span style="color: rgb(160, 176, 192); font-style: italic;">1<wbr></wbr></span><span style="color: rgb(16, 96, 160);">&lt;?php</span><br><span style="color: rgb(160, 176, 192); font-style: italic;">2<wbr></wbr></span><span style="color: rgb(91, 54, 116); font-style: italic;">$transport</span><span><wbr></wbr></span><span style="color: rgb(32, 32, 32);">=</span><span><wbr></wbr></span><span style="color: rgb(0, 112, 32); font-weight: bold;">array</span>(<span style="color: rgb(64, 112, 160);">'foot'</span><span style="color: rgb(32, 32, 32);">,</span><span><wbr></wbr></span><span style="color: rgb(64, 112, 160);">'bike'</span><span style="color: rgb(32, 32, 32);">,</span><span><wbr></wbr></span><span style="color: rgb(64, 112, 160);">'car'</span><span style="color: rgb(32, 32, 32);">,</span><span><wbr></wbr></span><span style="color: rgb(64, 112, 160);">'plane'</span>);<br><span style="color: rgb(160, 176, 192); font-style: italic;">3<wbr></wbr></span><span style="color: rgb(91, 54, 116); font-style: italic;">$mode</span><span><wbr></wbr></span><span style="color: rgb(32, 32, 32);">=</span><span><wbr></wbr></span><span style="color: rgb(76, 143, 47); font-weight: bold;">current</span>(<span style="color: rgb(91, 54, 116); font-style: italic;">$transport</span>);<span><wbr></wbr></span><span style="color: rgb(160, 176, 192); font-style: italic;">// $mode = 'foot';</span><br><span style="color: rgb(160, 176, 192); font-style: italic;">4<wbr></wbr></span><span style="color: rgb(91, 54, 116); font-style: italic;">$mode</span><span><wbr></wbr></span><span style="color: rgb(32, 32, 32);">=</span><span><wbr></wbr></span><span style="color: rgb(76, 143, 47); font-weight: bold;">next</span>(<span style="color: rgb(91, 54, 116); font-style: italic;">$transport</span>); <wbr><wbr><span style="color: rgb(160, 176, 192); font-style: italic;">// $mode = 'bike';</span><br><span style="color: rgb(248, 16, 176);">5<wbr></wbr></span><span style="color: rgb(91, 54, 116); font-style: italic;">$mode</span><span><wbr></wbr></span><span style="color: rgb(32, 32, 32);">=</span><span><wbr></wbr></span><span style="color: rgb(76, 143, 47); font-weight: bold;">next</span>(<span style="color: rgb(91, 54, 116); font-style: italic;">$transport</span>); <wbr><wbr><span style="color: rgb(160, 176, 192); font-style: italic;">// $mode = 'car';</span><br><span style="color: rgb(160, 176, 192); font-style: italic;">6<wbr></wbr></span><span style="color: rgb(91, 54, 116); font-style: italic;">$mode</span><span><wbr></wbr></span><span style="color: rgb(32, 32, 32);">=</span><span><wbr></wbr></span><span style="color: rgb(76, 143, 47); font-weight: bold;">prev</span>(<span style="color: rgb(91, 54, 116); font-style: italic;">$transport</span>); <wbr><wbr><span style="color: rgb(160, 176, 192); font-style: italic;">// $mode = 'bike';</span><br><span style="color: rgb(160, 176, 192); font-style: italic;">7<wbr></wbr></span><span style="color: rgb(91, 54, 116); font-style: italic;">$mode</span><span><wbr></wbr></span><span style="color: rgb(32, 32, 32);">=</span><span><wbr></wbr></span><span style="color: rgb(76, 143, 47); font-weight: bold;">end</span>(<span style="color: rgb(91, 54, 116); font-style: italic;">$transport</span>); <wbr><wbr><span><wbr></wbr></span><span style="color: rgb(160, 176, 192); font-style: italic;">// $mode = 'plane';</span><br><span style="color: rgb(160, 176, 192); font-style: italic;">8<wbr></wbr></span><span style="color: rgb(16, 96, 160);">?&gt;</span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> </div> <br><br><br> current(PHP 3, PHP 4, PHP 5)<br> current -- 返回数组中的当前单元<br> 说明<br><br> mixed current ( array &amp;array )<br><br> 每个数组中都有一个内部的指针指向它“当前的”单元,初始指向插入到数组中的第一个单元。<br> current() 函数返回当前被内部指针指向的数组单元的值,并不移动指针。如果内部指针指向超出了单元列表的末端,current() 返回 FALSE。<br><br> 警告<br> 如果数组包含有空的单元(0 或者 "",空字符串)则本函数在碰到这个单元时也返回 FALSE。这使得用 current() 不可能判断是否到了此数组列表的末端。要正确遍历可能含有空单元的数组,用 each() 函数。<br><br> 例 1. current() 及相关函数的用法示例<br><div style="font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(240, 240, 240); font-family: Consolas, 'Lucida Console', 'Courier new'; color: rgb(32, 32, 32);"> <span style="color: rgb(160, 176, 192); font-style: italic;">1<wbr></wbr></span><span style="color: rgb(16, 96, 160);">&lt;?php</span><br><span style="color: rgb(160, 176, 192); font-style: italic;">2<wbr></wbr></span><span style="color: rgb(91, 54, 116); font-style: italic;">$transport</span><span><wbr></wbr></span><span style="color: rgb(32, 32, 32);">=</span><span><wbr></wbr></span><span style="color: rgb(0, 112, 32); font-weight: bold;">array</span>(<span style="color: rgb(64, 112, 160);">'foot'</span><span style="color: rgb(32, 32, 32);">,</span><span><wbr></wbr></span><span style="color: rgb(64, 112, 160);">'bike'</span><span style="color: rgb(32, 32, 32);">,</span><span><wbr></wbr></span><span style="color: rgb(64, 112, 160);">'car'</span><span style="color: rgb(32, 32, 32);">,</span><span><wbr></wbr></span><span style="color: rgb(64, 112, 160);">'plane'</span>);<br><span style="color: rgb(160, 176, 192); font-style: italic;">3<wbr></wbr></span><span style="color: rgb(91, 54, 116); font-style: italic;">$mode</span><span><wbr></wbr></span><span style="color: rgb(32, 32, 32);">=</span><span><wbr></wbr></span><span style="color: rgb(76, 143, 47); font-weight: bold;">current</span>(<span style="color: rgb(91, 54, 116); font-style: italic;">$transport</span>);<span><wbr></wbr></span><span style="color: rgb(160, 176, 192); font-style: italic;">// $mode = 'foot';</span><br><span style="color: rgb(160, 176, 192); font-style: italic;">4<wbr></wbr></span><span style="color: rgb(91, 54, 116); font-style: italic;">$mode</span><span><wbr></wbr></span><span style="color: rgb(32, 32, 32);">=</span><span><wbr></wbr></span><span style="color: rgb(76, 143, 47); font-weight: bold;">next</span>(<span style="color: rgb(91, 54, 116); font-style: italic;">$transport</span>); <wbr><wbr><span style="color: rgb(160, 176, 192); font-style: italic;">// $mode = 'bike';</span><br><span style="color: rgb(248, 16, 176);">5<wbr></wbr></span><span style="color: rgb(91, 54, 116); font-style: italic;">$mode</span><span><wbr></wbr></span><span style="color: rgb(32, 32, 32);">=</span><span><wbr></wbr></span><span style="color: rgb(76, 143, 47); font-weight: bold;">current</span>(<span style="color: rgb(91, 54, 116); font-style: italic;">$transport</span>);<span><wbr></wbr></span><span style="color: rgb(160, 176, 192); font-style: italic;">// $mode = 'bike';</span><br><span style="color: rgb(160, 176, 192); font-style: italic;">6<wbr></wbr></span><span style="color: rgb(91, 54, 116); font-style: italic;">$mode</span><span><wbr></wbr></span><span style="color: rgb(32, 32, 32);">=</span><span><wbr></wbr></span><span style="color: rgb(76, 143, 47); font-weight: bold;">prev</span>(<span style="color: rgb(91, 54, 116); font-style: italic;">$transport</span>); <wbr><wbr><span style="color: rgb(160, 176, 192); font-style: italic;">// $mode = 'foot';</span><br><span style="color: rgb(160, 176, 192); font-style: italic;">7<wbr></wbr></span><span style="color: rgb(91, 54, 116); font-style: italic;">$mode</span><span><wbr></wbr></span><span style="color: rgb(32, 32, 32);">=</span><span><wbr></wbr></span><span style="color: rgb(76, 143, 47); font-weight: bold;">end</span>(<span style="color: rgb(91, 54, 116); font-style: italic;">$transport</span>); <wbr><wbr><span><wbr></wbr></span><span style="color: rgb(160, 176, 192); font-style: italic;">// $mode = 'plane';</span><br><span style="color: rgb(160, 176, 192); font-style: italic;">8<wbr></wbr></span><span style="color: rgb(91, 54, 116); font-style: italic;">$mode</span><span><wbr></wbr></span><span style="color: rgb(32, 32, 32);">=</span><span><wbr></wbr></span><span style="color: rgb(76, 143, 47); font-weight: bold;">current</span>(<span style="color: rgb(91, 54, 116); font-style: italic;">$transport</span>);<span><wbr></wbr></span><span style="color: rgb(160, 176, 192); font-style: italic;">// $mode = 'plane';</span><br><span style="color: rgb(160, 176, 192); font-style: italic;">9<wbr></wbr></span><span style="color: rgb(16, 96, 160);">?&gt;</span></wbr></wbr></wbr></wbr></wbr></wbr> </div> <br></wbr></wbr>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值