danrah Posted July 7, 2008 Share Posted July 7, 2008 I have two one-dimensional arrays starting from index 0. The first array stores the complete list of students' names and has (for example) 500 elements and the second array consists of a part of the larger array. How can i extract the elements that exist in the first array and not in the second array. Thanks in advance, Link to comment https://forums.phpfreaks.com/topic/113563-solved-comparing-two-arrays-and-extract-the-differences/ Share on other sites More sharing options...
Wolphie Posted July 7, 2008 Share Posted July 7, 2008 Use array_diff() <?php $array1 = array("a" => "green", "red", "blue", "red"); $array2 = array("b" => "green", "yellow", "red"); $result = array_diff($array1, $array2); print_r($result); ?> Result: Array ( [1] => blue ) Manual: http://uk3.php.net/manual/en/function.array-diff.php Link to comment https://forums.phpfreaks.com/topic/113563-solved-comparing-two-arrays-and-extract-the-differences/#findComment-583479 Share on other sites More sharing options...
danrah Posted July 7, 2008 Author Share Posted July 7, 2008 thanks, but my arrays contain unicode characters and it doesn't work. What should i do then? Link to comment https://forums.phpfreaks.com/topic/113563-solved-comparing-two-arrays-and-extract-the-differences/#findComment-583552 Share on other sites More sharing options...
danrah Posted July 8, 2008 Author Share Posted July 8, 2008 Thanks, But the problem was stem from an additional whitespace that was fixed after using trim(). Link to comment https://forums.phpfreaks.com/topic/113563-solved-comparing-two-arrays-and-extract-the-differences/#findComment-584245 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.