note 89121 deleted from control-structures.switch by thiago

From: Date: Mon, 23 Feb 2009 14:57:11 +0000
Subject: note 89121 deleted from control-structures.switch by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-151014@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- @sedativchunk Just use array_rand and you don't have to write so much code... As quantifier you can add the same value more than one time to the data array. Furthermore you should not use count() in a for loop, because it is executed each time. Use a variable or foreach instead. At last you can save some code at the array definition. If you want to add a new link you don't have to write "$name[] = " each time, which can save you a lot of time. <?php // Create set of links $links = array( '<a href="whatever.html">page 1</a>', '<a href="whatever.html">page 2</a>', '<a href="whatever.html">page 3</a>', '<a href="whatever.html">page 4</a>', '<a href="whatever.html">page 5</a>', '<a href="whatever.html">page 6</a>', '<a href="whatever.html">page 7</a>', '<a href="whatever.html">page 8</a>' ); $font_sizes = array('11', '11', '16', '18', '20'); // Create loop to display links foreach ($links as $link) { // Get random font size $font_size = array_rand($font_sizes); // Display the link echo '<span style="font-size: ' .$font_sizes[$font_size]. ';">' .$link. '</span>&nbsp;&nbsp;'; } ?>

« previous php.notes (#151014) next »