How to use rsort in PHP
In this article, I will explain how the rsort() function can be used in PHP.
rsort() function in PHP
-
The rsort() function is used to sort an array by the values in reverse order.
-
The rsort() function assigns new keys for the elements in the array.
-
In rsort() function, Existing keys will be removed.
-
The rsort() function returns TRUE on success, or FALSE on failure.
Syntax
Parameter
- array array is required parameter. the specified array to be sort.
-
sorttype sorttype is optional parameter. it determine, how to sort the array values. Possible values of sorttype is
- SORT_REGULAR - this is the default case value. it don't change types.
- SORT_NUMERIC - it's treat values numerically.
- SORT_STRING - it's treat values as strings.
- SORT_LOCALE_STRING - it's treat values as strings, based on local settings.
Example
The following example show to how the rsort() function can be used in PHP.
<html>
<body>
<h3 style="color: grey;">rsort() function example in PHP</h3>
<?php
$subject_array = array("Hindi", "English", "Math", "Computer");
rsort($subject_array);
foreach ($subject_array as $key => $val)
{
echo "subject[ " . $key . "] = " . $val . "<br />";
}
?>
</body>
</html>
|
Output
You may also want to read these related articles here
Got a programming related question? You may want to post your question here