# 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 (  => Array (  => c  => 8  => z )  => Array (  => a  => 5  => x )  => Array (  => b  => 3  => 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 (  => Array (  => 1  => e )  => Array (  => 2  => f )  => Array (  => 3  => g ) ) </xmp></pre>

#php     #array     #multidimensional-array