# Questions #Tagged [array]

Questions: 3

#### 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

#### How to create array of arrays using array_map() in php?

We can create array of arrays using array_map() function in PHP. To do this we have to pass null as parameter in place of functionName parameter and the list of arrays to create an array of arrays.<br> <pre><xmp><?php \$a = array(1, 2, 3); \$b = array("e", "f", "g"); \$result = array_map(null, \$a, \$b); print_r(\$result); ?> </xmp></pre> <pre><xmp> Output: Array ( [0] => Array ( [0] => 1 [1] => e ) [1] => Array ( [0] => 2 [1] => f ) [2] => Array ( [0] => 3 [1] => g ) ) </xmp></pre>

#php     #array     #multidimensional-array