Find even and odd no in an array using PHP

Find even and odd no in an array using PHP

i have written this program to find out even and odd numbers in an array

PHP Function used


array()
count($array)

Loop used 

for loop

conditional logic used

If
else



<?php
$no=array(1,21,53,84,50,66,7,38,9);
$countno=count($no);
echo $countno;
for($key=0; $key<$countno; $key++)
{

if ($no[$key] % 2 == 0)
{echo "This ".$no[$key]. " is an even<br>";

}

else
{
print  "This no ".$no[$key]."is an odd no <BR>";
}

}
?>



If you know some other method feel free to share in comments. 
Share on Google Plus

About Rahul Rana

I am an experienced web designer and SEO expert. I am running my own online marketing company i.e "SEO To Web Design". Thanks for reading, keep sharing online marketing and web design knowledge.
    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment

Enter your email address:

Delivered by FeedBurner