17.02.2017, 14:08
PHP код:
new
highest = 0, // Variable to store the current highest number of votes.
topscore = -1 // Variable to store the option with the highest number of votes.
;
for(new i = 0; i != sizeof(votes); i++) // Start a loop to iterate through all elements of the array 'votes'.
{
if(votes[i] > highest) // If the number of votes of this option is higher than the current highest...
{
highest = votes[i]; // Replace the current highest number of votes with the amount of votes that this option has.
topscore = i; // Option 'i' now has the highest number of votes.
}
}
return topscore;
Eg.
PHP код:
if(votes[0] > votes[1] && votes[0] > votes[2]) // Option '0' has the highest number of votes.
else if(votes[1] > votes[0] && votes[1] > votes[2]) // Option '1' has the highest number of votes.
else if(votes[2] > votes[0] && votes[2] > votes[1]) // Option '2' has the highest number of votes.