sandy1028 Posted June 30, 2008 Share Posted June 30, 2008 Hi, Two arrays array_1=array(A,B,C); arry_2=array(A,A,B,B,A,B,A,B); How to find out the element which is not in arry_2. Here in the above example the element should show as C. Link to comment https://forums.phpfreaks.com/topic/112551-array-compare/ Share on other sites More sharing options...
kenrbnsn Posted June 30, 2008 Share Posted June 30, 2008 Here's one way using the array_unique() and the array_diff() functions: <?php $array_1=array('A','B','C'); $array_2=array('A','A','B','B','A','B','A','B'); $array_3 = array_diff($array_1,array_unique($array_2)); echo '<pre>' . print_r($array_3,true) . '</pre>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/112551-array-compare/#findComment-578013 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.