Compare two arrays to see if value from form post exists in PHP

<?php
$choices = array('my choice 1', 'my choice 2', 'my choice 3');
 
$valid = true;
if (is_array($_GET['inputArray'])) {
    $valid = true;
    foreach($_GET['inputArray'] as $input) {
        if (!in_array($input, $choices)) {
           $valid = false;
        }
    }
 
	if ($valid) {
       echo "Input Value were found in choices";
    }
}
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.