oo7 oo7 - 1 month ago 7
PHP Question

How to increment by 3 in PHP

$arr = array('cat','dog','spider','snake');
$arrlength = count($arr);

$a = 1;
$i = 0;

while($a <= 3) :?>
<div class="col-sm-4">
<?php for($x=$i; $x < $arrlength;$x++):?>
<div class="checkbox">
<label>
<input type="checkbox" name="name[]" value="" <?php echo $name?>><?php echo $arr[$x]?><br/>
</label>
</div>
<?php endfor; ?>
</div>
<?php $a++; endwhile;?>


How do I increment the value of $i by 3 every increment of $a?

Thanks for your responce.

Answer

Try this:

$i = 0;

$i += 3;

or

$i = $i + 3;