Reputation: 515
Pl advise on PHP IF statement. How to use it twice like where an ad script when count of listing reaches 4th number and 9th number on a page with multiple listing
When used with below code it does not works in.
<?php
$listings = explode("<hr/>", $list);
$numberOfListings = count($listings);
for($i = 0; $i < $numberOfListings; ++$i)
{
if ($i == 4)
{ ?>
<some ad script runs in>
if ($i == 9)
{ ?>
<some ad script runs in>
<?php }
echo $listings[$i] . "<hr/>";
}
?>
Upvotes: 0
Views: 659
Reputation: 22721
Can you try this, Added $Reset
variable so every loop >10 it reset the count
<?php
$listings = explode("<hr/>", $list);
$numberOfListings = count($listings);
$Reset =1;
for($i = 0; $i < $numberOfListings; ++$i)
{
if ($Reset == 4)
{ ?>
<some ad script runs in>
<?php } if ($Reset == 9) { ?>
<some ad script runs in>
<?php }
echo $listings[$i] . "<hr/>";
if($Reset>10){
$Reset =1;
}
$Reset++;
}
?>
Upvotes: 2