Jared Stenquist » Archive of 'Aug, 2011'

Printing a randomly ordered list from an array with php

A recent project of mine required that I print out a link of online stores in a random order, so that no store has more exposure at the top of the list than others. This is the solution I came up with using PHP.

<?
// all of your items to shuffle go here
$links = array('<a href="http://www.google.com">Google</a>',
                 '<a href="http://www.yahoo.com">Yahoo</a>',
                 '<a href="http://www.ebay.com">EBay</a>',
                 '<a href="http://www.cnn.com">CNN</a>',
                 '<a href="http://www.wsj.com">Wall Street Journal</a>'                
                 );

// this shuffles up the array order
shuffle($links);

// let's create a unordered list to display the items
    echo "<ul>";
    
// here's where all the items get printed    
foreach ($links as $link) {
    echo "<li>$link</li>";
    }

// closing the unordered list    
    echo "</ul>";
?>
Posted in programming

You can tell a lot about a person

water or coffee
mac or pc
aol or gmail
car or bike
club or dive bar
take photo or be the photo
sit or stand
rent or buy
cook or take-out
read or watch
talk or listen
write or type
txt or call

Stereotypes aside it’s an interesting world we live in

 

 

 

 

Posted in Uncategorized