How to use current in PHP
In this article, I will explain how the current() function can be used in PHP.
current() function in PHP
- The current() function is used to return the value of the current element in an array.
- In current() function, every array has an internal pointer to its "current" element, which is initialized to the first element into the array.
- The current() function returns FALSE on empty elements.
Syntax
Parameter
- array array is required parameter. it is the input array.
Example
The following example show to how the current() function can be used in PHP.
<html>
<body>
<h3 style="color: Red;">current() function example in PHP</h3>
<?php
$subject_list = array('Hindi', 'English', 'Math', 'Science');
$subject = current($subject_list);
print "$subject <br />";
$subject = next($subject_list);
print "$subject <br />";
$subject = current($subject_list);
print "$subject <br />";
$subject = prev($subject_list);
print "$subject <br />";
$subject = end($subject_list);
print "$subject <br />";
$subject = current($subject_list);
print "$subject <br />";
?>
</body>
</html>
|
Output
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here