freelance84 Posted September 17, 2010 Share Posted September 17, 2010 Just a quick one, new area for me. I have an array which is looped against another array, if the two values from each ever match then an event occurs, if not then something else. If a match does occur i then want to remove the said value from one of the arrays... is this really all i need to do, seems too simple: unset($saved_dont_use[$j]); Quote Link to comment Share on other sites More sharing options...
Andy-H Posted September 17, 2010 Share Posted September 17, 2010 //get unique array values $diff = array_diff($arr1, $arr2); if (!empty($diff)) { //event trigger unset($arr1); //all unique values stored in $diff, $arr2 keeps all values. } else { //event trigger } Will that do or do you need to trigger an event for each value matched? foreach($arr1 as $k => $v) { if ( in_array($arr1[$k], $arr2) ) { //values matched, trigger event unset($arr1[$k]); // $arr1 contains unique values, $arr2 remains the same. } else { // no values matched, trigger other event. } } Quote Link to comment Share on other sites More sharing options...
freelance84 Posted September 20, 2010 Author Share Posted September 20, 2010 Yea thanks, I think the second method you posted will work. Is it not really a good idea to remove a value from an array with just the unset function? Quote Link to comment Share on other sites More sharing options...
freelance84 Posted September 21, 2010 Author Share Posted September 21, 2010 Thanks Andy-H, using "in_array" works like a charm. That's one more function learnt Quote Link to comment 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.