Populate Array During Loop With in_array

From: Date: Thu, 06 Mar 2003 13:37:22 +0000
Subject: Populate Array During Loop With in_array
Groups: php.db 
Request: Send a blank email to php-db+get-26118@lists.php.net to get a copy of this message
Can somebody please tell me why the $displayThese variable in the code snippet below only gets populated with the last value in the $newsList array even when $newsList has more than one row of data? while($newsList = mysql_fetch_array($result_getNews)){ if($convReadList != ""){ for($i = 0; $i < $countNewsItems; $i++){ if (!in_array($newsList[$i], $convReadList)){ //echo $newsList[$i]." was found\n"; $displayThese[$i] = $newsList[$i]; } } } else{ echo "<p>readList is empty</p>"; } } print_r($displayThese); $result_getNews is a small associative array of news article IDs drawn from a MySQL db query. I know it has more than one row because I can print_r it and see the data in the array. Furthermore, the echo... line below, the loop prints out the IDs I expect to see. However, when I attempt to put them into the $displayThese array, I only get the last news article ID in the result set. If the my $result_getNews variable holds an associative array ([0]=>2,[1]=>4,[2]=>6) and $convReadList is ([0]=>4) then the following output is produced: 2 was found6 was found but print_r($displayThese) produces Array([0]=>6) which is the last result in the $resultGetNews set. I have echoed and print_r() -ed every single variable to check its contents and they all contain exactly what I expect them too up until that last print_r($displayThese). Is this related to the way in_array works, to the way an associative array works or am I not populating the $displayThese array properly? Or have I just been staring at this same code for waaaaay too long and am missing something obvious? Help is appreciated. Thanks, Rich

« previous php.db (#26118) next »