homepage Welcome to WebmasterWorld Guest from 107.21.163.227
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe and Support WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
How do you randomise large chunks of code?
internetheaven




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

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.

 

lucy24




msg:4623881
 11:36 pm on Nov 16, 2013 (gmt 0)

$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?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved