array prev function - return the value of previous element of an array
array-prev-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 prev function - return the value of previous element of an array</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 prev function - return the value of previous element of an array">
<meta name="keywords" content="php, example, code, array, function, prev">
<meta name="description" content="array prev function - return the value of previous element of an array">
<style>
h2, h4{background:#ddd; color:#000058;}
h2{ padding:3px; margin:3px; font-size:21px;}
h4{ padding:2px; margin:2px; font-size:18px;}
p{padding:2px; margin:2px; color:#003366;}
body{ background:#FFFFFb;}
</style>
</head>
<body>
<h2>array prev function - return the value of previous element of an array</h2>
<pre>
<?php
/*
--------------------------------------------------------------
lets make an array and fill-up it with some values
--------------------------------------------------------------
*/
$myArray = array("apple");
array_push($myArray, "zoo");
array_push($myArray, "cow");
array_push($myArray, "book");
echo "<h4>Output of myArray</h4>";
print_r($myArray);
/*
-------------------------------------------------------------------------------------
we want to get the previous element's value of the array that the internal array pointer
pointed to by using array prev function
-------------------------------------------------------------------------------------
*/
$currentElement = current($myArray);
$nextElement = next($myArray);
$previousElement = prev($myArray);
echo "<h4>Output of previousElement of the array using array prev function</h4>";
print "<p>$"."currentElement = {$currentElement}</p>";
print "<p>$"."nextElement = {$nextElement}</p>";
print "<p>$"."previousElement = {$previousElement}</p>";
?>
</pre>
</body>
</html>

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