Example of current, next, and reset function usage in php, currentreset
This article describes the usage of current, next, and reset functions in php. Share it with you for your reference.
The Code is as follows:
Copy codeThe Code is as follows: $ array = array ('step one', 'Step two', 'Step three ', 'Step four'); // defines an array
Echo current ($ array). "<br/> n"; // returns the first element of the array.
Next ($ array); // The array pointer moves one bit behind
Next ($ array); // The array pointer moves one bit behind
Echo current ($ array). "<br/> n"; // returns the current element of the array, the third value.
Reset ($ array); // pointer to the first value of the array
Echo current ($ array). "<br/> n"; // returns the first value of the array.
//
$ Info = array ('red', 'blue', 'green'); // defines an array.
While ($ result = current ($ info ))
{
Echo $ result;
Echo "<br> ";
Next ($ info );
}
//
$ Array = array (
'Fruit1' => 'apple ',
'Fruit2' => 'Orange ',
'Fruit3' => 'grape ',
'Fruit4' => 'apple ',
'Fruit5' => 'apple'); // defines an array.
While ($ fruit_name = current ($ array) // obtain the current value of the array cyclically
{
If ($ fruit_name = 'apple') // if the current value is apple
{
Echo key ($ array). '<br/>'; // name of the key that outputs the current value
}
Next ($ array); // move the array pointer down one step
}
I hope this article will help you with PHP programming.