Merge two arrays and sort them as numbers, in descending order in PHP

Description

The following code shows how to merge two arrays and sort them as numbers, in descending order.

Example


//from ww w  .  j  a  v a2  s.c  om
<?php
    $a1=array(1,3,15,7,5);
    $a2=array(4,3,20,1,6);
    $num=array_merge($a1,$a2);
    array_multisort($num,SORT_DESC,SORT_NUMERIC);
    print_r($num);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone