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, Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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(). 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.