2

This is probably so newbie. Basically im l

$count_versions = array();
while ($row = mysql_fetch_array($result))
{
    $email_build = $row1['build_info'];
$count_versions[] = $email_build;
    }

Now when I use print_r I get this

Array ( [2660] => 8 [2662] => 6 [2655] => 6 [2666] => 1 ) 

Which is perfect, now all I want to do is to output those values like

2660 - 8 votes
2662 - 6 votes
2655 - 6 votes
2666 - 1 votes

When I try this it seems to break up the values back into a full array which undoes my array_count_values but I am stumped

I realize this foreach loop makes no sense but its as close as I can get, any ideas how I can basically print it out like print_r does it so i can put it in a table later

$i=0;
foreach ($count_versions as $version => $nums)
{
$i++;
echo "Version: " . $nums . " - " . $count_versions . "<br />";
}
1
  • Inside the foreach you have new values now: $version and $nums. Use them to get the data you need.
    – Peon
    Jan 4, 2013 at 10:10

2 Answers 2

4

It looks so easy to do it with a foreach:

$count_versions = array ( "2660" => 8, "2662" => 6, "2655" => 6, "2666" => 1 );

foreach ($count_versions  as $key => $value)  
    echo $key.' - '.$value.' votes<br>'; 
1
  • I guess i didnt ask the question clearly so sorry for that and i guess that made it hard for others to answer it, nonetheless the information in this one gave me an AHA moment, the problem was i was using foreach ($count_versions as $version => $nums) instead of foreach (array_count_values($count_versions) as $version => $nums) That caused me to see each loop individually instead of grouped which threw me off, thanks guys for guiding me. The reason i choose this answer although both were technically correct was it showed me my array was the problem Jan 4, 2013 at 11:13
2
echo "Version: " . $version . " - " . $nums . " votes<br />";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.