We learned about two ways to check if an array contain any value from another array in PHP. Output Yes, first array has atleast a value from the second array At the end of for loop we can check if our result value is true that means first array has at least a value from the secondary array. As soon as we find a value from the first array that exist in the second array we will mark our result as true and break the loop. If it returns true, then it means that the value exists in the second area. During iteration, for each value check if it exist in the second array or not using the in_array() function.įor this, we will pass this value and the second array as arguments to the in_array() function. To check if an array contains a value from the second array, we can iterate over all the elements of first array using foreach() function. Yes, first array has atleast a value from the second array
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |