Questions #Tagged [sorting]

Questions: 2

How to sort elements in array as per time parameter?

The time values in array can be sorted as strings. Below is the source code for same:<br> <pre><xmp>array.sort((a, b) => a.time.localeCompare(b.time)); console.log(array);</xmp></pre>

 

#node.js     #array     #sorting     #javascript    

How to sort Multi-dimensional Array using one of its parameter(dimension) in PHP?

Using below logic this multidimentional array can be sorted using parameter 1 which is $arr_count.<br> <pre><xmp>Code: $result = array_map(null, $arr_name, $arr_count,$arr_desc); $keys = array_column($result, '1'); //Here 1 means it will sort basis count, 0 means it will sort based on arr_name, 2 means it will sort based on arr_desc array_multisort($keys, SORT_DESC, $result); print_r($result);</xmp></pre> <pre><xmp>Result: Array ( [0] => Array ( [0] => c [1] => 8 [2] => z ) [1] => Array ( [0] => a [1] => 5 [2] => x ) [2] => Array ( [0] => b [1] => 3 [2] => y ) )</xmp></pre>

 

#php     #array     #multidimensional-array     #sorting