Question: I have some markup like so:

```
<div class="list">

    <article> content... </article>
    <article> content... </article>
    <article> content... </article>
    <article> content... </article>
    <article> content... </article>

</div>

```

What I want to do is make the order of what these articles appears on the page random. What would be the best and easiest way to do this?

I thought about doing some sort of length count and storing it in an array and then spitting them back out again in a random order. e.g.

```
$numbers = range(1, 20);
shuffle($numbers);
foreach ($numbers as $number) {
    echo "$number ";
}

```

Can anyone offer ideas etc? Thanks

**NOTE: These are not coming from a database!**

Answer: 
[Every day I'm shuffling!](http://php.net/manual/en/function.shuffle.php)

But yeah, having your contents in a PHP array, then displaying them all through a little `foreach` would be fine. Example :

```
$content = array('content1', 'content2', 'content3');
shuffle($content);
echo '<div>';
foreach($content as $value) {
  echo '<article>', $value, '</article>';
}
echo '</div>';

```
You could use DOMDocument.

```
$dom = new DOMDocument;

$dom->loadXML($html);

$articles = $dom->getElementsByTagName('article');

$articlesShuffled = array();

// What is a good way in PHP to turn an array-like object into a real array?    
foreach($articles as $article) {
           $articlesShuffled[] = $article;
}

shuffle($articlesShuffled);

foreach($articlesShuffled as $article) {
        $article->parentNode->appendChild($article);
}

echo $dom->saveHTML();

```

[CodePad](http://codepad.viper-7.com/NqMt0K).

I treated the input as XML because the `loadHTML()` method complains about the `article` element. I guess you'd need to supply a HTML5 doctype (or tell DOMDocument the schema) for that to work.