note 64124 deleted from function.fclose by sobak

From: Date: Thu, 01 Dec 2016 17:26:49 +0000
Subject: note 64124 deleted from function.fclose by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207887@lists.php.net to get a copy of this message
Note Submitter: williamhamby at williamhamby dot net ---- Trying to understand how 'end foreach' and 'endwhile' differ, I've encountered a problem I can't solve by myself. The following is a fairly easy stock portfolio script. Everything works, except at the end where I want to calculate the average of the gains as represented by $gain[$i]. <?php $quantity="3"; $stocks=array("iso","grn","bdgr.pk"); $buydates=array("3 jan 2006","1 feb 2006","3 apr 2006"); $prices=array("0.32","0.20","0.95"); $recommends=array("hold","strong buy","buy"); $i=0; echo"<tr>"; echo "\n<th align='center'>ticker</th>"; echo "\n<th align='center'>buy date</th>"; echo "\n<th align='center'>price $</th>"; echo "\n<th align='center'>recommend</th>"; echo "\n<th align='center'>value $</th>"; echo "\n<th align='center'>change %</th>\n</tr>\n"; foreach($stocks as $stock) { $fp=fopen("http://","r"); $data=fgetcsv($fp,1000,","); $values=$data[1]; echo "<tr>\n<td align='center'>".$stock."</td>"; echo "\n<td align='center'>".$buydates[$i]."</td>"; echo "\n<td align='center'>".$prices[$i]."</td>"; echo "\n<td align='center'>".$recommends[$i]."</td>"; echo "\n<td align='center'>".$values."</td>\n<td align='center'>"; echo $gain[$i]=round(((($values-$prices[$i])/$prices[$i])*100),2); echo "</td>\n</tr>"; fclose ($fp); $i++; } echo "\n<tr>\n<td align='center'>".$gain[$i]."<td>\n</tr>\n"; ?> Help?

« previous php.notes (#207887) next »