Advertisement
Guest User

Untitled

a guest
Dec 18th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. <?php
  2.  
  3. // Defining first array. This one is already sorted.
  4. $arr1 = [
  5.   '123',
  6.   '8E7',
  7.   '8EW',
  8.   '8S4',
  9.   '925',
  10.   '928',
  11.   '9S0',
  12.   '9SQ',
  13. ];
  14.  
  15. // Second array contains the same elements as the first one,
  16. // but it is not sorted.
  17. $arr2 = [
  18.   '123',
  19.   '925',
  20.   '928',
  21.   '8E7',
  22.   '8EW',
  23.   '8S4',
  24.   '9S0',
  25.   '9SQ',
  26. ];
  27.  
  28. // Perform sorting of first (already sorted) array
  29. sort($arr1);
  30.  
  31. // Perform sorting of first (already sorted) array
  32. sort($arr2);
  33.  
  34. // Print out checks. Sorted arrays should have the same elements
  35. // on the same positions
  36. for ($i = 0; $i < count($arr1); $i++) {
  37.     if ($arr1[$i] === $arr2[$i]) {
  38.         $status = 'OK';
  39.     } else {
  40.         $status = 'BUG';
  41.     }
  42.     echo $arr1[$i] . ' : ' . $arr2[$i] . ' : ' . $status . PHP_EOL;
  43. }
  44.  
  45. // Result:
  46. //
  47. //   123 : 123 : OK
  48. //   8E7 : 925 : BUG
  49. //   8EW : 928 : BUG
  50. //   8S4 : 8E7 : BUG
  51. //   925 : 8EW : BUG
  52. //   928 : 8S4 : BUG
  53. //   9S0 : 9S0 : OK
  54. //   9SQ : 9SQ : OK
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement