Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Defining first array. This one is already sorted.
- $arr1 = [
- '123',
- '8E7',
- '8EW',
- '8S4',
- '925',
- '928',
- '9S0',
- '9SQ',
- ];
- // Second array contains the same elements as the first one,
- // but it is not sorted.
- $arr2 = [
- '123',
- '925',
- '928',
- '8E7',
- '8EW',
- '8S4',
- '9S0',
- '9SQ',
- ];
- // Perform sorting of first (already sorted) array
- sort($arr1);
- // Perform sorting of first (already sorted) array
- sort($arr2);
- // Print out checks. Sorted arrays should have the same elements
- // on the same positions
- for ($i = 0; $i < count($arr1); $i++) {
- if ($arr1[$i] === $arr2[$i]) {
- $status = 'OK';
- } else {
- $status = 'BUG';
- }
- echo $arr1[$i] . ' : ' . $arr2[$i] . ' : ' . $status . PHP_EOL;
- }
- // Result:
- //
- // 123 : 123 : OK
- // 8E7 : 925 : BUG
- // 8EW : 928 : BUG
- // 8S4 : 8E7 : BUG
- // 925 : 8EW : BUG
- // 928 : 8S4 : BUG
- // 9S0 : 9S0 : OK
- // 9SQ : 9SQ : OK
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement