• 04-06-2016, 16:45:04
    #1
    Reveloper
    Merhaba,

    Yahu yıllardır php yazıyorum aptal gibi kalıyorum karşıma şu çıktığında

    1 saattir aptalca bişeyle uğraşıyorum arkadaşlar

    Her 5 valda bir ul tagı açıp kapayacak. örneğin:

    $arr=array(
    	"test 1",
    	"test 2",
    	"test 3",
    	"test 4",
    	"test 5",
    	"test 6",
    	"test 7",
    	"test 8",
    	"test 9",
    	"test 10",
    	"test 11",
    	"test 12",
    );
    
    lakin array 12 olunca ul u kapatmayı unutmayacak sistem
    <ul>
    	<li>test 1</li>
    	<li>test 2</li>
    	<li>test 3</li>
    	<li>test 4</li>
    	<li>test 5</li>
    </ul>
    
    <ul>
    	<li>test 6</li>
    	<li>test 7</li>
    	<li>test 8</li>
    	<li>test 9</li>
    	<li>test 10</li>
    </ul>
    
    <ul>
    	<li>test 11</li>
    	<li>test 12</li>
    </ul>
    şimdiden teşekkürler
  • 04-06-2016, 17:02:08
    #2
    <?php
    
    $arr=array(
       "test 1",
       "test 2",
       "test 3",
       "test 4",
       "test 5",
       "test 6",
       "test 7",
       "test 8",
       "test 9",
       "test 10",
       "test 11",
       "test 12",
    );
     
    ?>
    
    <?php $counter = 0; ?>
    <?php foreach ($arr as $key => $value) { ?>
    
       <?php if( $key % 5 == 0 ) { ?> <ul> <?php } ?>
          <?php $counter++; ?>
          <li><?=$value?></li>
       <?php if( $counter == 5 ) { ?> </ul> <?php $counter = 0; } ?>
    
    <?php } ?>
    <?php if( $counter != 0 ) { ?> </ul> <?php } ?>
    Çok iyi kodlama olmasa da iş görür
  • 04-06-2016, 17:24:18
    #3
    Burti adlı üyeden alıntı: mesajı görüntüle
    Merhaba,

    Yahu yıllardır php yazıyorum aptal gibi kalıyorum karşıma şu çıktığında

    1 saattir aptalca bişeyle uğraşıyorum arkadaşlar

    Her 5 valda bir ul tagı açıp kapayacak. örneğin:

    $arr=array(
    	"test 1",
    	"test 2",
    	"test 3",
    	"test 4",
    	"test 5",
    	"test 6",
    	"test 7",
    	"test 8",
    	"test 9",
    	"test 10",
    	"test 11",
    	"test 12",
    );
    
    lakin array 12 olunca ul u kapatmayı unutmayacak sistem
    <ul>
    	<li>test 1</li>
    	<li>test 2</li>
    	<li>test 3</li>
    	<li>test 4</li>
    	<li>test 5</li>
    </ul>
    
    <ul>
    	<li>test 6</li>
    	<li>test 7</li>
    	<li>test 8</li>
    	<li>test 9</li>
    	<li>test 10</li>
    </ul>
    
    <ul>
    	<li>test 11</li>
    	<li>test 12</li>
    </ul>
    şimdiden teşekkürler
    foreach( array_chunk($arr, 5) as $lists ){
    
    	echo "<ul>";
    
    	foreach($lists as $list)
    		echo "<li>" .$list. "</li>";
    	
    
    	echo "</ul>";
    
    }