Question

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>
Était-ce utile?

La solution

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);

Autres conseils

Without foreach;

$iCounter = 2;
$iCount = 10;

for ($k = 1; $k <= $iCounter; $k++) {
    for ($i = 0; $i <= $iCount; $i++) {
        // do anything you need
        echo $i;
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top