array asort function - sort the given array maintaining regular order
asort-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>asort function - sort the given array maintaining regular 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="asort function - sort the given array maintaining regular order">
<meta name="keywords" content="php, example, code, array, function, asort">
<meta name="description" content="asort function - sort the given array maintaining regular order">
</head>
<body>
<h3>asort function - sort the given array maintaining regular order</h3>
<?php
/*
-----------------------------------------------------------
make an array and fill up with some keys and values
-----------------------------------------------------------
*/
$myArray = array("a"=>"apple","z"=>"zoo","c"=>"cat","b"=>"book");
echo "<p style='background:#eee; color:red;'>Output of myArray</p>";
echo "<pre>";
print_r($myArray);
echo "</pre>";
/*
-------------------------------------------------------------------------------------
we want to sort the array according to values and keep maintaining the regular order
by using asort function
-------------------------------------------------------------------------------------
*/
asort($myArray);
echo "<p style='background:#bbb; color:red;'>Output of sorted array using asort function by values</p>";
echo "<pre>";
print_r($myArray);
echo "</pre>";
?>
</body>
</html>

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