homepage Welcome to WebmasterWorld Guest from 23.20.61.85
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
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

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4623871 posted 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

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



 
Msg#: 4623871 posted 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.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved