How many multiple 5 is in 25 using php [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How many multiple 5 is in 25 using php [closed]



Please am looking for a code or php function that can help me know how many 5 is in 25
the code below only returns 5,10,15,20
i want something that will tell 4 instead of breaking the division point
thanks in advance


for($i = 1; $i < 25; $i++)

if ($i % 5 == 0)

echo $i;

;



This question appears to be off-topic. The users who voted to close gave this specific reason:





Check your math, there is 5, 5's in 25 not 4, also confused as to why your not simply doing echo 25 / 5;
– Lawrence Cherone
Aug 13 at 0:40



echo 25 / 5;





@LawrenceCherone Their issue is a programmatical one, not general knowledge of the number of 5s in 25. E.g. the for statement will stop when reaching "25" and this won't count the final set of 5s. This is a genuine programming error and is answerable.
– James
Aug 13 at 1:08



for




2 Answers
2



The reason is you limit your loop to stop when it hits 25. It will only loop when value is less than 25, so as soon as it reaches 25 it wont loop and so wont get your final set of 5s.



Try this:


for ($i = 1; $i <= 25; $i++)

if ($i % 5 == 0)
echo $i;

;



isn't this just a simple division (25%5=5)?
the reason why your code gives your 4 is because you are actually not getting to 25 (the loop stops when i=25), if you will usefor($i=0;$i<=25;$i++) the loop will still run when I=25, and so it will show you 5.


for($i=0;$i<=25;$i++)

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered