-
- // Quickly determine whether $a array is a subset of $b array
- $a = array(135,138);
- $b = array(135,138,137);
Copy code
implementation method:
Method 1, for loop traversal
-
-
$flag = 1;
- foreach ($a as $va) {
- if (in_array($va, $b)) {
- continue;
- }else {
- $flag = 0;
- break;
- }
- }
-
- if ($flag) {
- echo "Yes";
- }else {
- echo "No";
- }
Copy code
Method 2, use of PHP method to determine whether an array is a subset of another array
Code:
-
-
$c = PHP method to determine whether an array is a subset of another array($a, $b);
- print_r($c);
- $flag = empty($c)?1 : 0;
-
- if ($flag ) {
- echo "Yes";
- }else {
- echo "No";
- }
Copy code
Method 3, use of PHP method to determine whether an array is a subset of another array
Example:
-
-
if ($a == PHP method to determine whether an array is a subset of another array($a, $b)) {
- $flag = 1;
- }else {
- $flag = 0;
- }
-
- if ($ flag) {
- echo "Yes";
- }else {
- echo "No";
- }
Copy code
|