I have 2 tables: dt_times and dt_reports
dt_times contains a list of times, and dt_reports contains votes (positive / negative) at the corresponding time points.
My code does the following:
- Picks all the time until today
- For each of these periods - calculates margin
((positive-negative)/positive)*100 - The result is stored in an array.
After all iterations, here is var_dump id => margin
array(8) { [111]=> int(100) [110]=> int(-100) [108]=> int(-100) [100]=> int(100) [97]=> int(100) [92]=> int(100) [59]=> float(-71.4285714286) [58]=> float(-50) }
I need to select the highest stock, where id is also the highest. Since you can see that 111, 100, 97 and 92 - all have the same value of 100.
My code so far has been as follows:
while ($row = mysql_fetch_array($result)) { //Get values for quality //calculate margin $arr[$row['id']] = $margin; $arr2[$margin] = $row['id']; } $timeId = $arr2[max($arr)];
However, after all cycles, $ timeId is 92, which is the last id in the array, which has a value of 100
I think array_keys might be the answer, but for the love of my life I could not understand them = (
source share