Search for Multiple Values in PHP Array | 2023 Code Examples

search for multiple values in PHP array
How to search for multiple values in a PHP array Create a variable that includes the array to be searched Create a separate variable that includes all of the values you want to search and find. Set a new variable that will include all of your final results Run the array_intersect function passing the array to be searched as the first parameter and the searching array as the second parameter. Assign the array_intersect results to your final results variable. Verify your results with a print_r or var_dump statement. Remove the print_r statement and continue processing requirements Searching multiple values in a PHP array Code Snippet <?php //An array with random country names. $country_arr = array("USA","Canada","Mexico","Germany","Italy"); //Look for these values and return the intersection. $search_values = ["USA","Canada","France"]; //It would contain the result of the array_filter intersection $intersection_arr = array_intersect($country_arr,$search_values); print_r($intersection_arr); /* OUTPUT Array ( [0] => USA [1] => Canada )…

read more