array arsort function - sort the given array reverse order
arsort-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 arsort function - sort the given array reverse order</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 arsort function - sort the given array reverse order">
<meta name="keywords" content="php, example, code, array, function, arsort">
<meta name="description" content="array arsort function - sort the given array reverse order">
</head>
<body>
<h3>array arsort function - sort the given array reverse order</h3>
<?php
/*
-----------------------------------------------------------
let us make an array and fill up with some keys and values
-----------------------------------------------------------
*/
$myArray = array("a"=>"apple","c"=>"cat","b"=>"book","z"=>"zoo");
echo "<p style='background:#aaa; color:#000077;'>Output of myArray</p>";
echo "<pre>";
print_r($myArray);
echo "</pre>";
/*
-------------------------------------------------------------------------------------
we want to sort the array reverse order by using arsort function
sorting is based on values rather than keys
-------------------------------------------------------------------------------------
*/
arsort($myArray);
echo "<p style='background:#ddd; color:#000077;'>Output of sorted array using arsort function by values</p>";
echo "<pre>";
print_r($myArray);
echo "</pre>";
?>
</body>
</html>

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