Jump to content

[SOLVED] Compare one value of array against all the values of another


Hatdrawn

Recommended Posts

How would I build a function that would test each key of one associative array to all the values of another arry?

 

This is what I have, quite clearly not it but hey, I'm trying

 

foreach($_POST as $var => $value)
{
$n=0;
if($var == $arr_auto[$n]){
echo $var . ' : ' . $value . "<br>";
}
$n++;
}

$array1 = array ('a' => 1,'b' => 1,'c' => 1);
$array2 = array ('a','b','d');
$newarray = array_intersect_key($array1,array_flip($array2));
  
echo "<pre>";
print_r($newarray);

 

output:

Array
(
    [a] => 1
    [b] => 1
)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.