neprasa Posted March 29, 2007 Report Share Posted March 29, 2007 piemeram ir $a="a";$a="a";$a="a";$a="a";$a="a";$a="a"; un tad echo $a ka uztaisit lai katrs tresais $a butu ieks <b></b> Link to comment Share on other sites More sharing options...
bubu Posted March 29, 2007 Report Share Posted March 29, 2007 Jau cik topiki bijuši... Pat satura rādītāja topikā ir. Še padomā: $i=0; echo "pirmais=", $i%3; $i++; echo "otrais=", $i%3; $i++; echo "trešais=", $i%3; $i++; echo "ceturtais=", $i%3; $i++; echo "piektais=", $i%3; $i++; echo "sestais=", $i%3; $i++; echo "septītais=", $i%3; ... Link to comment Share on other sites More sharing options...
neprasa Posted March 29, 2007 Author Report Share Posted March 29, 2007 (edited) <? $i=0; $a = $i%3; if("2"=="$a"){ echo "<b>trešais</b>"; } else {echo "1";} $i++; $a = $i%3; if("2"=="$a"){ echo "<b>trešais</b>"; } else {echo "2";} $i++; $a = $i%3; if("2"=="$a"){ echo "<b>trešais</b>"; } else {echo "3";} ?> teiksiet ka kods slikts Edited March 29, 2007 by neprasa Link to comment Share on other sites More sharing options...
4e4en Posted March 29, 2007 Report Share Posted March 29, 2007 liec to suda kodu iekš [ code] [/code] man sanak bišķi savādāk <? $menu = array( 'Viens', 'divi', 'trīs' ); $i=0; foreach($menu as $item) { if((++$i % 3) == 2) { echo '<b>',$item,'</b>'; }else echo $item; } ?> Link to comment Share on other sites More sharing options...
bubu Posted March 29, 2007 Report Share Posted March 29, 2007 neprasa: tu manu kodu pamēģināji? palaidi un paskatījies, ko tas izvada? Man pēc tava topika gan tā nemaz nešķiet. Link to comment Share on other sites More sharing options...
v3rb0 Posted March 30, 2007 Report Share Posted March 30, 2007 (edited) šinī gadījumā nemaz nevajag to $i atsevišķi skaitīt. $menu = array( 'Viens', 'divi', 'trīs', '4tais', '5tais','6tais','7tais'); foreach($menu as $i => $item) { if(($i+1) % 3) echo $item; else echo '<b>'.$item.'</b>'; } pie tam 4e4en, tavējais nestrādā.. iekrāso otro, un piekto, varbūt nākamreiz vispirms pārbaudi, tad māci citus. Edited March 30, 2007 by v3rb0 Link to comment Share on other sites More sharing options...
4e4en Posted March 30, 2007 Report Share Posted March 30, 2007 (edited) es neteicu, ka esmu to pārbaudijis.... es to uz fiksu roku ieklikšķināju.... bija slinkums domāt & no neprašas grūti ir saprast, ko tieši viņam vajag... un lai iekrāsotu katru trešo var darīt tā <?php $menu = array( 'Viens', 'divi', 'trīs', '4tais', '5tais','6tais','7tais'); $x = 0; foreach($menu as $item) { if(++$x == 3) { echo '<b>'.$item.'</b>'; $x = 0; }else{ echo $item; } } ?> vai šitā, lai iekrāsotu katru otro <?php $menu = array( 'Viens', 'divi', 'trīs', '4tais', '5tais','6tais','7tais'); $pr = true; foreach($menu as $item) { $pr = !$pr; if($pr) echo '<b>'.$item.'</b>'; else echo $item; } ?> atkal bija slinkums pārbaudīt Edited March 30, 2007 by 4e4en Link to comment Share on other sites More sharing options...
bubu Posted March 30, 2007 Report Share Posted March 30, 2007 4e4en: kurš no vārdiem "lai katrs tresais $a butu ieks <b></b>" tev nav skaidrs? Link to comment Share on other sites More sharing options...
4e4en Posted March 30, 2007 Report Share Posted March 30, 2007 Katrs trešais? Link to comment Share on other sites More sharing options...
bubu Posted March 30, 2007 Report Share Posted March 30, 2007 Katrs trešais vārds tev nav skaidrs? Link to comment Share on other sites More sharing options...
neprasa Posted April 11, 2007 Author Report Share Posted April 11, 2007 [ code] [/code] <? $menu = array( 'Viens', 'divi', 'trīs' ); $i=0; foreach($menu as $item) { if((++$i % 3) == 2) { echo '<b>',$item,'</b>'; }else echo $item; } ?> man sitais nestrada rada no 6 ierakstiem 4 ir ieks <b> un neka nevaru dabut lai ir tikai katrs 3. Link to comment Share on other sites More sharing options...
andrisp Posted April 11, 2007 Report Share Posted April 11, 2007 Paeksperimentēt nemaz negribam. <?php $menu = array(1,2,3,4,5,6,7,8,9,10,11); $i=0; foreach($menu as $item) { if((++$i % 3) == 0) { echo '<b>',$item,'</b>'; } else { echo $item; } } ?> Link to comment Share on other sites More sharing options...
4e4en Posted April 12, 2007 Report Share Posted April 12, 2007 Professionāli trennēts sliņķis :D Link to comment Share on other sites More sharing options...
Recommended Posts