mardi 30 juin 2015

Php Array Count to run script run for each reply till 3rd reply and not more than that

I have a Forum in which adscript is displayed after every reply

<?php if( count( $replies ) <= 3 ){ ?>

---- script ----

<?php } ?>  

Earlier there was a clause that there could be maximum 3 replies per Forum post - but now that clause is changed and there are 5, 7 or 10 replies even

I want to modify code so EVEN If there are more than 3 replies - then script should run after each reply till 1st 3 replies and not from 4th reply onwards

I believe an array is to used likely

<?php
$replyCount = 0;
foreach( $replies as $reply )
{
$replyCount++;
$replyNumber = array(1, 2, 3);

if (in_array($replyCount, $replyNumber)) {
echo "script";
}
?>

But - what the above script is doing is that

Its displaying the script in all replies

Its displaying script 3 times after each reply

Can some one help and advise in modification so that

Script should run once after each reply

Script should run till 3rd reply and not more than that

Pls help and advise

Aucun commentaire:

Enregistrer un commentaire