Created
May 21, 2012 18:56
-
-
Save thefrosty/2763961 to your computer and use it in GitHub Desktop.
Random array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ads = array('<a href="#">Sponsored link 1</a>', '<a href="#">Sponsored link 2</a>', '<a href="#">Sponsored link 3</a>'); | |
echo $ads[array_rand($ads, 1)]; | |
OR | |
$numb = rand( 1, 3 ); | |
if ( $numb == 1 ) | |
echo '<a href="#">Sponsored link 1</a>'; |
Because each array is a different message..
Ah, your initial example showed them as the same except for the number, in that case scenario 1 is probably my preferred approach, but I'd list each element in the array on each line since they're long strings, it's easier to read/modify later
The first method will probably look cleaner than the other depending on how many different links you end up with.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
why not this?