array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'function.next.php', 1 => 'next', ), 'up' => array ( 0 => 'ref.array.php', 1 => '配列 関数', ), 'prev' => array ( 0 => 'function.natsort.php', 1 => 'natsort', ), 'next' => array ( 0 => 'function.pos.php', 1 => 'pos', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'reference/array/functions/next.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
next — 配列の内部ポインタを進める
next() は、ひとつの違いを除いて current() と同じです。 next() は要素を返す前に内部配列ポインタをひとつ先に進めます。 つまり、次の配列要素を返すとともに内部配列ポインタをひとつ進めるということです。
array
対象となる配列。
内部配列ポインタが指す場所の次の場所の値を返します。
それ以上要素がない場合は false
を返します。
バージョン | 説明 |
---|---|
8.1.0 | この関数を object に対してコールすることは、推奨されなくなりました。 object に対して最初に get_mangled_object_vars() を使って配列に変換するか、ArrayIterator のような Iterator を実装したクラスのメソッドを使ってください。 |
7.4.0 | SPL クラスのインスタンスは、プロパティを持たない空のオブジェクトのように扱われるようになりました。これより前のバージョンでは、この関数と同じ名前の Iterator のメソッドをコールしていました。 |
例1 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';
?>