Jump to content

ttmt_73

New Members
  • Posts

    2
  • Joined

  • Last visited

ttmt_73's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I need to create structure like this <div class="row"> <div class="col-sm-3"> <!--content loop 1--> </div> <div class="col-sm-3"> <!--content loop 1--> </div> <div class="col-sm-3"> <!--content loop 2--> </div> <div class="col-sm-3"> <!--content loop 2--> </div> </div> <div class="row"> <div class="col-sm-3"> <!--content loop 3--> </div> <div class="col-sm-3"> <!--content loop 3--> </div> <div class="col-sm-3"> <!--content loop 4--> </div> <div class="col-sm-3"> <!--content loop 4--> </div> </div> I need to create it in a single foreach loop but on each loop I only create this structure. <div class="col-sm-3"> <!--content loop 1--> </div> <div class="col-sm-3"> <!--content loop 1--> </div> I thought I had it working with this. But this seems to skip the 3rd element in the array. <div class="row"> <?php $i = 0; foreach(....../*your code*/){ if($i == 2){ $i = 0; ?> </div><div class="row"> <?php } else { ?> <div class="col-sm-3"> <!--content--> </div> <?php $i++; } } ?> </div> I have a demo here to illustrate - http://viper-7.com/EsGoc9
  2. Hi all I have an array of phrases. I'd like to randomly pick phrases from the array in a loop. I don't want to pick the same phrase more then once in the loop. I thought I could randomly pick the phrase and then delete it before the next loop. http://codepad.org/11l0nStX <?php for($i=0; $i<16; $i++){ $phrases = array('Hello Sailor','Acid Test','Bear Garden','Botch A Job','Dark Horse', 'In The Red','Man Up','Pan Out','Quid Pro Quo','Rub It In','Turncoat', 'Yes Man','All Wet','Bag Lady','Bean Feast','Big Wig'); $ran_Num = array_rand($phrases); $ran_Phrase = $phrases[$ran_Num]; unset($phrases[$ran_Phrase]); echo $ran_Phrase."\r\n"; echo count($phrases)."\r\n"; } ?> Is it possible to randomly pick a different phrase from the array on each loop.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.