Test if one array is a subset of another

前端 未结 6 1311
庸人自扰
庸人自扰 2021-02-13 05:59

How can I determine if one array is a subset of another (all elements in the first are present in the second)?

 $s1 = \"string1>string2>string3>string4&         


        
6条回答
  •  走了就别回头了
    2021-02-13 06:40

    Simple: use array subtraction.

    On array subtraction, you will know whether or not one array is a subset of the other.

    Example:

    if (!array_diff($array1, $array2)) {
        // $array1 is a subset of $array2
    }
    

    Reference: array_diff

    You can use array_intersect also.

提交回复
热议问题