sort. Sorting hash   [3.4.4]


The given method sorts the hash fields according to the specified function.

Sorting_function is the function, whose current value determines the position of the field in the final (sorted) variant of the hash. This value may be a string (values are compared in alphabetical order) or a number (values are compared as float numbers).

Sorting_direction determines sorting direction. The parameter may have two values:
Ascending value is used by default.

<br />]

As the result of this code, the
$men hash will be sorted according to the name values:
Alex: 20
Mishka: 29 
y: 26 

You may sort the hash by age values in descending order (
desc) if you substitute the line of the code which is calling method sort for this one:

The code will result in:
Mishka: 29
Sergey: 26
Alex: 20

Copyright © 1997–2017 Art. Lebedev Studio | Last updated: 30.03.2016