In this paper, we describe the simple intersection, difference set and set function of PHP implementation. Share to everyone for your reference, as follows:
<?PHP$ARR1 = Array (' 0 ' = ' zero ', ' 1 ' = ' = ' one ', ' 2 ' = ' + ', ' 3 ' = ' three '); $arr 2 = Array (' 2 ' = ' ", ' t Hree ' + ' three ', ' 4 ' = ' Four ', ' 5 ' = ' five ');//Difference Set "The comparison returns the values in ARR1 but not in the ARR2 and any other parameter arrays. "$array _diff = Array_diff ($arr 1, $arr 2); echo "<pre>"; Print_r ($array _diff);/* Output Results *array* (* [0] = zero* [1] = one*) *///intersection "The comparison returns values that are both in arr1 and in the ARR2 array. Note: Key values remain arr1 the key values in the array are constant $array_intersect = Array_intersect ($arr 1, $arr 2); echo "<pre>"; Print_r ($array _intersect);/* Output Result *array* (* [2] = two* [3] = three*) *///and set "append the values in the ARR1 array to the ARR2 array. Returns an array as the result. "#注意事项:" If the input array has the same string key name, the value following the key name overrides the previous value. #然而, if the array contains numeric key names, subsequent values will not overwrite the original values, but are appended to the back. "$array _merge = Array_merge ($arr 1, $arr 2); echo "<pre>"; Print_r ($array _merge);/* Output result * array* (* [0] = zero* [1] = = one* [2] = = two* [3] = = three* [4] = = two* [th REE] = three* [5] = four* [6] = = five*) */?>
Operation Result: