note 89121 added to control-structures.switch

From: Date: Mon, 23 Feb 2009 04:04:55 +0000
Subject: note 89121 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-151004@lists.php.net to get a copy of this message
@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;'; } ?> ---- Server IP: 212.124.37.9 Probable Submitter: 85.181.232.176 ---- Manual Page -- http://www.php.net/manual/en/control-structures.switch.php Edit -- https://master.php.net/note/edit/89121 Del: integrated -- https://master.php.net/note/delete/89121/integrated Del: useless -- https://master.php.net/note/delete/89121/useless Del: bad code -- https://master.php.net/note/delete/89121/bad+code Del: spam -- https://master.php.net/note/delete/89121/spam Del: non-english -- https://master.php.net/note/delete/89121/non-english Del: in docs -- https://master.php.net/note/delete/89121/in+docs Del: other reasons-- https://master.php.net/note/delete/89121 Reject -- https://master.php.net/note/reject/89121 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#151004) next »