Idea: first set two subscripts, initialize them as the starting addresses of the two arrays respectively, and push forward in sequence. The advancing rule is to compare the numbers in two arrays. the subscript of the small array is pushed forward until the subscript of any array reaches the end of the array. if the same number is not touched yet, it indicates that the array does not have the same number.
PHP checks whether two ordered arrays have the same sample code analysis number.
$ Arr1 [$ I] & $ counter = 0) {$ start = $ j; $ counter ++ ;}}$ counter = 0; // the next cycle begins, reset to 0}
Method 2:
Idea: first set two subscripts, initialize them as the starting addresses of the two arrays respectively, and push forward in sequence. The advancing rule is to compare the numbers in two arrays. the subscript of the small array is pushed forward until the subscript of any array reaches the end of the array. if the same number is not touched yet, it indicates that the array does not have the same number.
$arr2[$j]) {$j ++;}else {$i ++;}}
The above is the details of PHP code analysis to determine whether the same number sample exists in two ordered arrays. For more information, see other related articles in the first PHP community!