Gets the value of the first element of the unknown character key name array through the PHP current function

  • 2020-06-22 23:56:06
  • OfStack

About the current() function:

Each array has an internal pointer to its "current" cell, initially pointing to the first cell inserted into the array. Obtained with current().

Similar functions:

end() moves the internal pointer of array to the last cell and returns its value.

next() returns the value of the next cell to which the pointer inside the array points, or FALSE when there are no more cells.

prev() returns the value of the first cell indicated by the pointer inside the array, or FALSE when there are no more cells.

reset() reverses the internal pointer to array back to the first cell and returns the value of the first array cell, or FALSE if the array is empty.

Take the following PHP case:

 
<?php 
$arr = array("a"=>"php","java","c"); 
echo current($arr); //php 
echo next($arr); //java 
echo prev($arr); //php  Pointing up 1 The value of the cell, so it's zero again php the  
echo end($arr); //c 
?> 


Very nice and useful php functions, I remember them anyway.

Related articles: