W3docs

PHP: Check if an array contains all array values from another array

You can use the array_diff function in PHP to compare two arrays and check if the first array contains all of the values from the second array.

You can use the array_diff function in PHP to compare two arrays and check if the first array contains all of the values from the second array.

Example of using the array_diff function in PHP to compare two arrays

php— editable, runs on the server
Info

Watch a video course: Learn object oriented PHP

You can also use array_intersect to check if all elements of second array are present in first array.

Example of using the array_intersect function in PHP to compare two arrays

php— editable, runs on the server