Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7924305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:41:43+00:00 2026-06-03T17:41:43+00:00

$legend = array(); $color[] = (‘000000’, ‘ff0000’, ‘fasd3f’); foreach ($stats as $row) { if

  • 0
$legend = array();
$color[] = ('000000', 'ff0000', 'fasd3f');
    foreach ($stats as $row) {

        if ($row->countofmsg > 0) {

            array_push($legend, "<div class='legend_label'><div class='color-block' style='background:#".$color.";'></div>".ucwords($row->msg)."<div class='legend_count'>$row->count</div></div><div class='clear'></div>");

        }

    }

Here is my code, what I would like to do is set an array of colors $color[], and then inside the foreach loop array, call the first color in the array and then call the second and third and so forth with each thing the foreach spits out. And then repeat at the beginning of the colors array when it reaches the last color in the array.

Would kick out something like:

(color1) msg - count
(color2) msg - count
(color3) msg - count
etc..

Please let me know if there is a duplicate question, I tried researching for it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T17:41:44+00:00Added an answer on June 3, 2026 at 5:41 pm

    This assumes that your $stats array is integer indexed

    $legend = array();
    $color[] = ('000000', 'ff0000', 'fasd3f');
    $colorCount = count($color);
    foreach ($stats as $k => $row) {
        if ($row->countofmsg > 0) {
                $legend[] = "<div class='legend_label'><div class='color-block' style='background:#".$color[ ($k % $colorCount) ].";'></div>".ucwords($row->msg)."<div class='legend_count'>$row->count</div></div><div class='clear'></div>";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to generate this html hierarchy in my zend_form display group: <div class=settings>
I have the following code in my main index.php: <div class=form> <?php $oForm =
So I have a Radio button group, like so: <div data-role=fieldcontain> <fieldset data-role=controlgroup> <legend>Choose
I'm trying to color code text in a legend. (Since I'm trying to sort
<div id=rightsidesix > <?php echo '<div class=class_color_title ><b>'.Polls.'</b></div>'; ?> <?php echo '<div id=id_color_polls >';
i have the following text <fieldset> <ul id=ContentPlaceHolder2_1g class=profList column ui-sortable> <legend class=group>المجموعه 1</legend>
Legend tags are always a nuisance as they don't adhere to a lot of
How to set the legend to overlay on the right of the excel chart
I'm drawing a legend on an axes object in matplotlib but the default positioning
Why is my legend faded in these examples below? Notice how the colours in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.