Usage examples of current, next and reset functions in php, currentreset
The example in this article describes the usage of current, next and reset functions in php. Share it with everyone for your reference.
The specific code is as follows:
Copy code The code is as follows:
$array=array('step one','step two','step three',' step four'); //Define an array
echo current($array)."
n"; //Return the first element of the array
next($array); //Move the array pointer back one position
next($array); //Move the array pointer back one position
echo current($array)."
n"; //Return the current element of the array, the third value
reset($array); //The pointer points to the first value of the array
echo current($array)."
n"; //Return the first value of the array
//
$info=array('red','blue','green'); //Define array
while($result=current($info))
{
echo $result;
echo "
";
next($info);
}
//
$array=array(
'fruit1'=>'apple',
'fruit2'=>'orange',
'fruit3'=>'grape',
'fruit4'=>'apple',
'fruit5'=>'apple'); //Define array
while($fruit_name=current($array)) //Loop to get the current value of the array
{
if($fruit_name=='apple') //If the current value is apple
{
echo key($array).'
'; //Output the key name of the current value
}
next($array); //Move the array pointer down one step
}
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/912675.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/912675.htmlTechArticleUsage examples of current, next and reset functions in php, currentreset This article describes the current, next and reset functions in php usage. Share it with everyone for your reference. The specific code is as follows:...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn