N-Bomb(Nerd) Posted May 16, 2010 Share Posted May 16, 2010 Hi, I have two arrays ($StateList_1, $StateList_2) of states that I'm trying to compare. The arrays look like this: //$StateList_1 Array ( [illinois] => 97 [Connecticut] => 88 [Delaware] => 97 [Montana] => 96 [Georgia] => 82 [Ohio] => 91 ) //$StateList_2 Array ( [illinois] => 97 [Connecticut] => 88 [Delaware] => 97 [Montana] => 96 [Georgia] => 82 [Ohio] => 84 [Texas] => 91 ) I'm trying to compare the two arrays using the state name (the keys of the arrays). The numbers serve a different purpose later on in my script, so just ignore those for now. What I'm trying to do is compare $StateList_1 with $StateList_2. I've tried doing this: foreach(array_keys($StateList_1) as $StateName) { if(!in_array($StateName, array_keys($StateList_2))) { echo "Missing: " . $StateName . "<br>"; } } However, that doesn't seem to be working so well. Suggestions? Link to comment https://forums.phpfreaks.com/topic/201957-comparing-array/ Share on other sites More sharing options...
N-Bomb(Nerd) Posted May 16, 2010 Author Share Posted May 16, 2010 Anyone? :'( Link to comment https://forums.phpfreaks.com/topic/201957-comparing-array/#findComment-1059191 Share on other sites More sharing options...
kenrbnsn Posted May 16, 2010 Share Posted May 16, 2010 Take a look at array_diff_key ken Link to comment https://forums.phpfreaks.com/topic/201957-comparing-array/#findComment-1059199 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.