PHP 陣列current和next用法分享

codeceo發表於2015-03-05

本文這裡通過示例給大家簡單對比分析了PHP 陣列current和next的用法,雖然示例很簡單,但是對於我們理解current和next非常有幫助,這裡推薦給大家。

1.current

<?php
 $transport = array('foot', 'bike', 'car', 'plane');
 $mode = current($transport); //$mode = 'foot';
 $mode = next($transport);   // $mode ='bike';
 $mode = current($transport); //$mode = 'bike';
 $mode = prev($transport);   // $mode ='foot';
 $mode = end($transport);    // $mode ='plane';
 $mode = current($transport); //$mode = 'plane';
 ?>

2.next

<?php
 $transport = array('foot', 'bike', 'car', 'plane');
 $mode = current($transport); //$mode = 'foot';
 $mode = next($transport);   // $mode ='bike';
 $mode = next($transport);   // $mode ='car';
 $mode = prev($transport);   // $mode ='bike';
 $mode = end($transport);    // $mode ='plane';
 ?>

示例很簡單,但是卻很實用,希望小夥伴們能夠喜歡。

相關文章