Welcome to WebmasterWorld Guest from 174.129.135.89

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

How do you randomise large chunks of code?

   
10:38 pm on Nov 16, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have this:

$item1 = "a really, really, really long chunk of code"
$item2 = "another really, really, really long chunk of code"

$random = '$item1#$item2#$item2#$item2';

$random = explode('#', $random);
shuffle($random);
$random = implode('#', $random);
$random1 = substr($random, 0, strpos($random, '#')).'';

$random2 = '$item1#$item2#$item2#$item2';

$random = explode('#', $random);
shuffle($random);
$random = implode('#', $random);
$random3 = substr($random, 0, strpos($random, '#')).'';

echo $random1;
echo $random3;


which actually prints $item1 or $item2 on the page. It doesn't, (as I'd hoped), display the large chunk of code for each item.
11:36 pm on Nov 16, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



$random = '$item1#$item2#$item2#$item2'

Wouldn't it have to be
$item1 . '#' . $item2 ... et cetera?

What I really wondered though is why you even need to do this. Wouldn't it be more efficient to make each numbered item (is it actually item3, item4 etc or are you mixing three from column B with one from column A?) a separate named function, and just randomize the four names?