Hatdrawn Posted June 11, 2009 Share Posted June 11, 2009 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++; } Quote Link to comment https://forums.phpfreaks.com/topic/161756-solved-compare-one-value-of-array-against-all-the-values-of-another/ Share on other sites More sharing options...
Hatdrawn Posted June 11, 2009 Author Share Posted June 11, 2009 foreach($_POST as $var => $value) { $n=0; if(in_array($var, $arr_auto)){ echo $var . ' : ' . $value . "<br>"; } $n++; } This is what I wanted, thought I'd post for someone elses reference Quote Link to comment https://forums.phpfreaks.com/topic/161756-solved-compare-one-value-of-array-against-all-the-values-of-another/#findComment-853469 Share on other sites More sharing options...
Cardale Posted June 11, 2009 Share Posted June 11, 2009 This gives a good basic understanding..now put it into a class and use a template system and see if you can get away with that. Quote Link to comment https://forums.phpfreaks.com/topic/161756-solved-compare-one-value-of-array-against-all-the-values-of-another/#findComment-853475 Share on other sites More sharing options...
Hatdrawn Posted June 11, 2009 Author Share Posted June 11, 2009 This gives a good basic understanding..now put it into a class and use a template system and see if you can get away with that. So what is wrong with this technique? It's the only solution I could find. Quote Link to comment https://forums.phpfreaks.com/topic/161756-solved-compare-one-value-of-array-against-all-the-values-of-another/#findComment-853484 Share on other sites More sharing options...
.josh Posted June 11, 2009 Share Posted June 11, 2009 $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 ) Quote Link to comment https://forums.phpfreaks.com/topic/161756-solved-compare-one-value-of-array-against-all-the-values-of-another/#findComment-853531 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.