Page is a not externally linkable
CyBerAliEn - 9:04 pm on Feb 8, 2010 (gmt 0)
Hmm... I just re-read your post, and you want a way to retrieve the item with the most votes!
Well, you can easily make a new "wrapper" function that utilizes the above function. Such as this:
function poll_getWinner($array)
{
//This function requires that the 'array' input be in the form provided by poll_arrayize()
$output = array();
$votes = $array['votes'];
$max = max($votes);
$maxKey = array_search($max,$votes);
$output['count'] = $max;
$output['choice'] = $array['choices'][$maxKey];
$output['choiceIndex'] = $maxKey;
//Function Output
return $output;
}
This function requires that the "record array" (produced by poll_arrayize function) be fed into it. This function will then return an associative array in the form:
Array
(
[count] => 12
[choice] => I'll use both
[choiceIndex] => 2
)
So, all in all... here is how you can make it all work out:
<?php
$record = "a:1:{i:1;a:3:{s:8:\"question\";s:27:\"Will you switch over to VX?\";s:6:\"choice\";a:3:i:1;s:3:\"Yes\";i:2;s:2:\"No\"; i:3;s:17:\"I'll use both\";}s:5:\"votes\";a:3:{i:1;i:5;i:2;i:7;i:3;i:12;}}}";
$recordArray = poll_arrayize($record);
$winner = poll_getWinner($recordArray);
echo "<p>The winner of the poll <b>{$recordArray['question']} is "{$winner['choice']}" with a total vote of <b>{$winner['count']}</b>.</b></p>";
?>
Since the functions turn the string into a useful array, you can manipulate it a lot easier to fit your needs.