문제

i need a sequence like this in a range from 0 to 10 with PHP. The result would be:

0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10 ........

I want to insert this function inside a foreach

UPDATE

<?php $count = 0; ?>
<div class="<?php echo 'minipost-'. $count++ ; ?>">
<?php
get_template_part( 'content', get_post_format() );
?>
</div>
도움이 되었습니까?

해결책

You already mentioned the solution in your question. You can use:

range(0, 10)

To repeat the sequence 3 times you could do:

str_repeat(implode(' ',range(0, 10)).' ', 3);

다른 팁

Without foreach;

$iCounter = 2;
$iCount = 10;

for ($k = 1; $k <= $iCounter; $k++) {
    for ($i = 0; $i <= $iCount; $i++) {
        // do anything you need
        echo $i;
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top