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. Link to comment https://forums.phpfreaks.com/topic/229467-question-matching-an-array-in-php/ 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) ?> Link to comment https://forums.phpfreaks.com/topic/229467-question-matching-an-array-in-php/#findComment-1182247 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! Link to comment https://forums.phpfreaks.com/topic/229467-question-matching-an-array-in-php/#findComment-1182248 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.