fork download
  1. <?php
  2.  
  3. // your code goes here
  4.  
  5. $nums1 = [];
  6. $nums2 = [1,2,3];
  7.  
  8. $num = array_merge($nums1,$nums2);
  9. array_multisort($num,SORT_ASC,SORT_NUMERIC);
  10.  
  11. print_r($num);
  12.  
  13. $length = count($num);
  14.  
  15. if($length % 2 == 0){
  16. $second_half_length = $length / 2;
  17. $first_half_length = $second_half_length - 1;
  18.  
  19. // Get index values
  20. $first_half = $num[$first_half_length];
  21. $second_half = $num[$second_half_length];
  22.  
  23. $median = ($first_half + $second_half) / 2;
  24. } else{
  25. $median = $num[$length / 2];
  26. }
  27. print_r($median);
Success #stdin #stdout 0.02s 26048KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
)
2