ev0 Posted March 3, 2011 Share Posted March 3, 2011 Basically i want to take an array of numbers let's say: <? $array1=array("1","2","3","4"); ?> Now say i reprint that same array, but the 3 is missing. <? $array2=array("1","2","4"); ?> How would i print what's missing from $array1 out of $array2? Sorry if this is confusing, i'll be happy to go into details if needed. Quote Link to comment Share on other sites More sharing options...
johnny86 Posted March 3, 2011 Share Posted March 3, 2011 <?php $arr1 = array(1, 2, 3, 4); $arr2 = array(1, 2, 4); $difference = array_diff($arr1, $arr2); // Returns all values from arr1 that are not present in arr2 print_r($difference); // Array(0 => 3) ?> Quote Link to comment Share on other sites More sharing options...
ev0 Posted March 3, 2011 Author Share Posted March 3, 2011 Oh wow, there really was a function already for that :'( Thanks a ton! 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.