StefanRSA Posted August 3, 2010 Share Posted August 3, 2010 Why is this not working??? If $adsused prints out: 1, 5, 6, 7, while ($tarray=mysql_fetch_array($admintotadsq)){ $adsused .= $tarray['adnr'].', '; } $array1 = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20); $array2 = array($adsused); $diff = array_diff($array1, $array2); print_r($diff); print_r($diff); prints out: Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 [9] => 10 [10] => 11 [11] => 12 [12] => 13 [13] => 14 [14] => 15 [15] => 16 [16] => 17 [17] => 18 [18] => 19 [19] => 20 ) What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/209638-array_diff-now-i-am-confused/ Share on other sites More sharing options...
sspoke Posted August 3, 2010 Share Posted August 3, 2010 replace $adsused .= $tarray['adnr'].', '; to $adsused[] = $tarray['adnr']; remove $array2 = array($adsused); replace $diff = array_diff($array1, $array2) with $diff = array_diff($array1, $adsused) should work. Quote Link to comment https://forums.phpfreaks.com/topic/209638-array_diff-now-i-am-confused/#findComment-1094464 Share on other sites More sharing options...
StefanRSA Posted August 3, 2010 Author Share Posted August 3, 2010 Thanks SSpoke! It works like a charm... Did the following to get the first entry of the array... $diff=(array_merge($diff)); $firstnum=$diff[0]; Quote Link to comment https://forums.phpfreaks.com/topic/209638-array_diff-now-i-am-confused/#findComment-1094469 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.