Note that there are some explanatory texts on larger screens.

plurals
  1. POHow Can I make this csv reading php code more efficient
    primarykey
    data
    text
    <p>OK, so I have the following code that reads a csv file that than outputs the result in the form of a HTML table:</p> <pre><code>$fhdrop = fopen("ac.csv", "r"); while (!feof($fhdrop) ) { $at[] = fgetcsv($fhdrop, 1024); } $fhdrop2 = fopen("rc.csv", "r"); while (!feof($fhdrop2) ) { $at2[] = fgetcsv($fhdrop2, 1024); } ?&gt; &lt;table border=1&gt; &lt;tr&gt; &lt;td&gt;a&lt;/td&gt; &lt;td&gt;b&lt;/td&gt; &lt;td&gt;c&lt;/td&gt; &lt;td&gt;d&lt;/td&gt; &lt;tr&gt; &lt;td&gt;&lt;?php echo $at[0][0] ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $at[0][1] ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo number_format($at[0][1]*$at2[0][1],2) ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo number_format($at[0][1]*$at2[1][1],2) ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;?php echo $at[1][0] ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $at[1][1] ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo number_format($at[1][1]*$at2[0][1],2) ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo number_format($at[1][1]*$at2[1][1],2) ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;?php echo $at[2][0] ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $at[2][1] ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo number_format($at[2][1]*$at2[0][1],2) ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo number_format($at[2][1]*$at2[1][1],2) ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;?php echo $at[3][0] ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $at[3][1] ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo number_format($at[3][1]*$at2[0][1],2) ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo number_format($at[3][1]*$at2[1][1],2) ?&gt;&lt;/td&gt; </code></pre> <p>Wag1 pplz!!! This account is mine now!!! </p> <p>The contents of ac.csv are:</p> <pre><code>a, 5, b, 10, c, 24, d, 21 </code></pre> <p>The contents of rc.csv are:</p> <pre><code>not, 1.87, notatall, 1.78 </code></pre> <p>As you can guess from the original code, in the second to columns I need a multiplication. So for example in the second row, third coloumn I need 5*1.87 and 5*1.78. So basically a*not and a*notatall.</p> <p>My code is not very efficient, how can I make it more efficient? I want all of these (somehow) put into a loop. It needs to have the exact same outcome, due to the complexity and the fact that it has 2d arrays, I have not yet been able to do this!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload