Create array with weighted items inserted at intervals
<p>I'm developing a messaging board for use in a client's lobby.</p>

<p>The "rundown" is JSON created from PHP, which is checked for updates by an AJAX call every 5 minutes. The rundown is populated from a MySQL database that contains the item, its duration and a start and stop time. JQuery iterates through the content then loops to the beginning of the data. Currently no items repeat within the list.</p>

<p>A weighting system has been requested, so that when an important item ($$$ client, staff meeting, etc) is present it appears more frequently in the list (instead of just once until the loop occurs).</p>

<p>I've added a weight column to the database, but am having trouble figuring out how to implement that in my final array build:</p>

<pre><code>$i = 0;
foreach ($rundown_standard as $item) {
            $return[$i]["playlist_id"] = $i;
            $return[$i]["item_id"] = $item["id"];
            $return[$i]["weight"] = $item["weight"];
            $return[$i]["duration"] = $item["duration"];
            $return[$i]["template"] = $item["template"];
            $return[$i]["headline"] = htmlentities($item["headline"]);

        $content = $helper-&gt;isJson($item["content"]);
        if ($content) {
            $return[$i]["content"] = $content; 
        } else { 
            $return[$i]["content"] = str_replace(array('{images_path_absolute}', '{images_path_relative}'), array(IMAGES_PATH_ABSOLUTE, IMAGES_PATH_RELATIVE), $item["content"]);
        }

    i++;
}
</code></pre>

<p><code>$return</code> is the formatted data I'm sending on to the function that calls this function.</p>

<p>The default weight is <code>0</code> which means it should be shown only once in the order it's added to the array, something with a weight of <code>90</code> should appear after every other item.</p>

<p>I've tried setting another counter variable and then inserting the item and resetting the counter, which would work for just one weighted item, but not for multiple weighted items</p>

<p>Clear as mud? </p>

<p>Thanks for any advice.</p>

<p>EDIT 17:45: The JavaScript is just to update the page dynamically; iterating through the JSON and appending the next item to a list:</p>

<pre><code>if (window.item_content[i].template == "1") {
    return '&lt;div class="featured-item" id="featured-item-'+window.item_content[i].playlist_id+'"&gt;&lt;img src="'+window.item_content[i].content+'" /&gt;&lt;/div&gt;';
}
</code></pre>

<p>It's the array where my problem lies, precisely how do I insert an element at a specified interval if there are multiple elements to insert.</p>
