array natsort function - natural order sorting
array-natsort-function-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 natsort function - natural order sorting</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 natsort function - natural order sorting">
<meta name="keywords" content="php, example, code, array, function, natsort">
<meta name="description" content="array natsort function - natural order sorting">
<style>
h2, h3, h4{background:#eee; color:#000059;}
h2{ padding:3px; margin:3px; font-size:20px;}
h3{ padding:2px; margin:2px; font-size:18px;}
h4{ padding:2px; margin:2px; font-size:15px;}
body{ background:#FFFFFc;}
</style>
</head>
<body>
<h2>array natsort function - natural order sorting</h2>
<pre>
<?php
/*
-----------------------------------------------------------
lets make an array and fill it up with some keys and values
-----------------------------------------------------------
*/
$myArray1 = array("zoo","apple","Zoo","book");
$myArray2 = array("zoo","apple","Zoo","book");
echo "<h4>Output of myArray1 and myArray2</h4>";
print_r($myArray1);
/*
-----------------------------------------------------------
output of the sorted array myArray1 by using regular sort
-----------------------------------------------------------
*/
echo "<h4>Output of myArray1 using regular sort</h4>";
sort($myArray1);
print_r($myArray1);
/*
-------------------------------------------------------------------------------------
we want to sort the array myArray2 natural order by using array natsort function
-------------------------------------------------------------------------------------
*/
natsort($myArray2);
echo "<h4>Output of sorted array myArray2 using array natsort function</h4>";
print_r($myArray2);
?>
</pre>
</body>
</html>

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