array reset function - reset array's internal pointer to first element and return it's value
array-reset-example-in-php.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>array reset function - reset array's internal pointer to first element and return it's value</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Md Iqbal Hosan">
<meta name="title" content="array reset function - reset array's internal pointer to first element and return it's value">
<meta name="keywords" content="php, example, code, array, function, reset">
<meta name="description" content="array reset function - reset array's internal pointer to first element and return it's value">
<style>
h2, h4{background:#eee; color:#000088;}
h2{ padding:3px; margin:3px; font-size:20px;}
h4{ padding:2px; margin:2px; font-size:19px;}
p{padding:2px; margin:2px; color:#003376;}
body{ background:#FFFFFa;}
</style>
</head>
<body>
<h2>array reset function - reset array's internal pointer to first element and return it's value</h2>
<pre>
<?php
/*
--------------------------------------------------------------
let us make an array and fill it up with some values
--------------------------------------------------------------
*/
$myArray = array("apple");
array_push($myArray, "zoo");
array_push($myArray, "cat");
array_push($myArray, "book");
echo "<h4>Output of myArray</h4>";
print_r($myArray);
/*
-------------------------------------------------------------------------------------
we want to set the internal array pointer to first element and get it's value
by using array reset function
-------------------------------------------------------------------------------------
*/
$currentElement = current($myArray);
$nextElement = next($myArray);
$resetElement = reset($myArray);
echo "<h4>Output of resetElement of the array using array reset function</h4>";
print "<p>$"."currentElement = {$currentElement}</p>";
print "<p>$"."nextElement = {$nextElement}</p>";
print "<p>$"."resetElement = {$resetElement}</p>";
?>
</pre>
</body>
</html>

No comments:
Post a Comment
leave your comments here..