Random ordering of a list

Discussion in 'PHP' started by wskmm, May 2, 2007.

  1. #1
    Looking to see if there is a simple php script that can take 4 or more items in a list
    (item a item b item c item d etc) and randomly order them.

    Thanks
     
    wskmm, May 2, 2007 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    
    $array_of_things = array( 'item 1', 'item 2', 'item 3', 'item 4', 'item 5' );
    $iterate = 5;
    for( $i = 0; $i < $iterate; $i++ ):
    	shuffle( $array_of_things );
    	echo "<br />\nCommencing....<br />\n";
    	echo implode("<br />\n", $array_of_things );
    endfor;
    
    PHP:
    certainly .....
     
    krakjoe, May 2, 2007 IP
  3. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #3
    
    <?php
    $array_of_things = array( 'item 1', 'item 2', 'item 3', 'item 4', 'item 5' );
    echo $array_of_things[ array_rand( $array_of_things ) ];
    ?>
    
    PHP:
    The more things that are in the list the better it'll work
     
    krakjoe, May 2, 2007 IP
  4. wskmm

    wskmm Peon

    Messages:
    112
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks very much
     
    wskmm, May 2, 2007 IP