reset函数的作用是将数组指针重置为指向数组的第一个元素,返回值
为该数组的第一个元素值,一般在遍历一个数组之前都要使用
reset函数对数组指针进行重定向。
end函数的作用是将数组指针指向最后一个元素,返回值为最后一个元素值,
如果数组为空,返回false值
prev函数返回值为数组array当前指针指向的元素的前一个元素
的后一个元素的值,如果当前为最后一个元素,则返回false值
current函数的作用就是返回数组array的当前元素值。如果指针指向了元素列表
的范围之外,返回false值
"abcus","b"=>"babble","c"=>"cacophony", "d"=>"dabble","e"=>"earring"); echo ""; echo "abcus babble cacophony dabble earring"; echo "
"; echo "current(\$data):"; echo current($data); echo ""; echo "
"; echo "prev(\$data):"; if ($var = prev($data)){ echo $var; }else echo "false"; echo ""; echo "
"; echo "current(\$data):"; if ($var = current($data)){ echo $var; }else echo "false"; echo ""; echo "
"; reset($data); echo "reset(\$data)"; echo "next(\$data):"; if ($var = next($data)){ echo $var; }else echo "false"; echo ""; echo "
"; echo "end(\$data)"; echo "prev(\$data);prev(\$data);prev(\$data);"; end($data); prev($data);prev($data);prev($data); while (list($key,$val)=each($data)){ echo "\$key=>\$vallue::"; echo "$key=>$val\n"; }?>
运行:
abcus babble cacophony dabble earring current($data) :abcus prev($data) :false current($data) :false reset($data) next($data) :babble end($data) prev($data);prev($data);prev($data); $key=>$vallue:: b=>babble $key=>$vallue:: c=>cacophony $key=>$vallue:: d=>dabble $key=>$vallue:: e=>earring