Navigating through Arrays

Every array has an internal pointer that points to the current element in the array. You want to move through an array.

Use:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN">
<head>
<title>PHP</title>
<meta Name="Author" Content="Hann So">
</head>
<body>
<p>
<?php
$fruits = array('Apples', 'Grapes', 'Bananas', 'Oranges');
print_r($fruits);
echo "<p><b>Navigating the array</b></p>";
echo "Current: ", current($fruits), "<br/>";
echo "Next: ", next($fruits), "<br/>";
echo "Prev: ", prev($fruits), "<br/>";
echo "End: ", end($fruits), "<br/>";
echo "<p><b>Reset the array</b></p>";
reset($fruits);
echo "Current: ", current($fruits), "<br/>";
?>
</p>
</body>
</html>

View the effect


Arrays (cintinued) | Adding all Values in an Array | Flipping an Array | Extracting Variables from Arrays | Imploding Arrays | Exploding Arrays | Navigating through Arrays | Merging Arrays | Comparing Arrays | Sorting Arrays | Creating Multidimensional Arrays | Sorting Multiple Arrays
© 2008: Hann So
email: hso@voyager.deanza.edu