SYNCERのロゴ
アイキャッチ画像

current - 現在、ポインタが指している要素の値を返す

currentは、現在、ポインタが指している要素の、値を返します。

構文

mixed current ( array &$array )

パラメータ

&$array

対象の配列。

返り値

mixed

現在、ポインタが指している要素の値。要素が存在しない場合はfalseが返る。

サンプルコード

<?php
	$array = [ "a", "b", "c", "d", "e" ] ;

	$response = current( $array ) ;

デモ

配列のポインタは、初期は最初の要素を指しています。

<?php
/*** このコードは編集できます。 ***/

	$array = [ "a", "b", "c", "d", "e" ] ;

	$response = current( $array ) ;

	var_dump( $response ) ;

next()で2つほど、ポインタを進めてから実行する例です。

<?php
/*** このコードは編集できます。 ***/

	$array = [ "a", "b", "c", "d", "e" ] ;

	next( $array ) ;
	next( $array ) ;

	$response = current( $array ) ;

	var_dump( $response ) ;

ポインタが存在しない位置を指している場合、falseが返ります。

<?php
/*** このコードは編集できます。 ***/

	$array = [ "a", "b", "c", "d", "e" ] ;

	next( $array ) ;
	next( $array ) ;
	next( $array ) ;
	next( $array ) ;
	next( $array ) ;
	next( $array ) ;
	next( $array ) ;
	next( $array ) ;
	next( $array ) ;
	next( $array ) ;

	$response = current( $array ) ;

	var_dump( $response ) ;
  • Twitterでシェア
  • Facebookでシェア
  • Google+でシェア
  • はてなブックマークでシェア
  • pocketに保存
  • LINEでシェア
更新履歴
2017年6月26日 (月)
コンテンツを公開しました。