Breaking

Saturday, February 29, 2020

php tutorial , How to use loops in php 7 with real world example ?

Here i am giving example that is useful in real world with if condition










<?php

//while loop

$count = 1;
while($count<=12){

if($count==1){
echo "<hr> <h1>hello</h1>- $count";
}else{
echo "<hr> <h4>hello</h4>- $count";
}
$count++;

}
 ?>

here you can see i have used first heading with h1 and other is h4, It will helpfull in some html website templates


While loop real world example :


Frontend result



Do while loop

<?php
//do while loop

$count = 1;
do{
if($count == 1){
echo "<h1>hello world</h1>";
}else{
echo "<p>lorem ipsum dummy text</p>";
}
$count++;
}while($count <= 5);

 ?>

Result :
















For loop 

<?php
//do while loop
for ($count = 0; $count <= 2; $count++) {
 ?>
<?php if($count==0){ ?>
<h1 style="color:green">What is Lorem Ipsum? </h1>
<?php }else{ ?>

<h1 style="color:black">What is Lorem Ipsum? </h1>
<?php } ?>
<p>Lorem Ipsum is simply
dummy text of the printing
and typesetting industry.
Lorem Ipsum has been the
industry's standard dummy text.</p>


<?php } ?>

result


















Foreach loop 

<?php
//comment in php
/* multiline */
$name = array("Raju", "Rakesh", "Jigar", "Sahil");

foreach ($name as $value) {
  echo "$value <br>";
}

?>

Result :














comment in php online by //comment
multi line comment in php /*content  */

Thank you for visiting my blog https://phptutorials99.blogspot.com/

No comments:

Post a Comment

your suggestion are welcome by me