compare two arrays & print matching array values
Display matching arrays values
Here in the below method, we created two arrays and assign to $users and $admins variables,now to compare these arrays we added for loop as shown below, and get count of $admins variable. In the previous article we had used arrays concept which will be useful for reference.
we had in_array() method to get the matching array values,let us know about in_array() method,it checks for existing array values,now let’s see syntax below
Here in the place of needle we need to add searched variable as $admins[i], which compares each and every value in $users and prints the matching values as below.
we can also display unique values in arrays by using array_unique() method,here in the below example we created array with duplicate values.
Thanks for reading this article