1. 程式人生 > >php函式current和next

php函式current和next

current輸出陣列中的當前元素
next輸出陣列下一個元素的值

案例一:

<?php
$people = array("Bill", "Steve", "Mark", "David");

echo current($people) . "<br>";
echo next($people);
#輸出結果
Bill
Steve

案例二:

$arr1 = array(XXXX);
$arr2 = array(XXXX);

$res = array();
$notId = array();

foreach ($arr2 as $key2 => $val2) {
    $res[$val2] = (int) current($arr1); //每次迴圈時返回arr1的當前值
    if (current($arr1) == false) {
        $notId[] = $val2;
    }
    next($arr1);//將arr1的指標移到下一個值
}