Random background color from array - PHP -


i beginner when comes programming wanted see if right way code this. trying generate random background color array.

if there i'm missing or there better please let me know.

<?php     $background_colors = array('#282e33', '#25373a', '#164852', '#495e67', '#ff3838');      $count = count($background_colors) - 1;      $i = rand(0, $count);      $rand_background = $background_colors[$i]; ?> <html>     <head>      </head>     <body style="background: <?php echo $rand_background; ?>;">      </body> </html> 

that's pretty good.

however, i'd array_rand()...

$background_colors = array('#282e33', '#25373a', '#164852', '#495e67', '#ff3838');  $rand_background = $background_colors[array_rand($background_colors)]; 

it less code , more readable imo.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -