note 91739 deleted from control-structures.switch by danbrown

From: Date: Wed, 24 Jun 2009 13:29:52 +0000
Subject: note 91739 deleted from control-structures.switch by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-157349@lists.php.net to get a copy of this message
Note Submitter: ped at 7gods dot org ---- sedativchunk: looks too complicated to me without any obvious or hidden benefit. What about this shortened version? <?php // Create set of links $link = array(); $link[] = '<a href="whatever.html">page 1</a>'; $link[] = '<a href="whatever.html">page 2</a>'; $link[] = '<a href="whatever.html">page 3</a>'; $link[] = '<a href="whatever.html">page 4</a>'; $link[] = '<a href="whatever.html">page 5</a>'; $link[] = '<a href="whatever.html">page 6</a>'; $link[] = '<a href="whatever.html">page 7</a>'; $link[] = '<a href="whatever.html">page 8</a>'; //proportional randomizer - ranges and values definition $fonts_sizes = array( 20 => 11, 30 => 16, 40 => 18, 50 => 20 ); //proportional randomizer - function (not exactly efficient, but KISS) function ProportionalRandomizer( $ranges_and_values_definition ) { $range_max = end( array_keys( $ranges_and_values_definition ) ); //will return 50 for $fonts_sizes $randomizer = rand( 1, $range_max ); foreach( $ranges_and_values_definition as $range => $value ) //will search for the proper range if ( $randomizer <= $range ) return $value; //and return it's value return end( $ranges_and_values_definition ); //should never happen :) } // Loop to display links for($i = 0; $i < count($link); ++$i) echo '<span style="font-size: ', ProportionalRandomizer( $fonts_sizes ), ';">', $link[$i], '</span>&nbsp;&nbsp;'; ?>

« previous php.notes (#157349) next »