「PHP」配列の先頭要素の値を返すサンプル

2020年11月15日

説明
reset ( array &$array ) : mixed
reset() は、array の内部ポインタの先頭の要素に戻し、
配列の最初の要素の値を返します。
PHPコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
$cft = array('ExampleOne', 'ExampleTwo', 'ExampleThree', 'ExampleFour');
// defaultポインタは先頭要素を指しています
echo current($cft) . "<br />\n";
// 次の2ステップをとばします
next($cft);
next($cft);
echo current($cft) . "<br />\n";
// ポインタをリセットし、再度ステップ1開始
reset($cft);
echo current($cft) . "<br />\n";
?>
<?php $cft = array('ExampleOne', 'ExampleTwo', 'ExampleThree', 'ExampleFour'); // defaultポインタは先頭要素を指しています echo current($cft) . "<br />\n"; // 次の2ステップをとばします next($cft); next($cft); echo current($cft) . "<br />\n"; // ポインタをリセットし、再度ステップ1開始 reset($cft); echo current($cft) . "<br />\n"; ?>
<?php

$cft = array('ExampleOne', 'ExampleTwo', 'ExampleThree', 'ExampleFour');

// defaultポインタは先頭要素を指しています
echo current($cft) . "<br />\n"; 

// 次の2ステップをとばします
next($cft);
next($cft);
echo current($cft) . "<br />\n";

// ポインタをリセットし、再度ステップ1開始
reset($cft);
echo current($cft) . "<br />\n"; 

?>

 

PHP

Posted by arkgame