سؤال

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