Last active
July 8, 2024 07:10
-
-
Save MakarandMane/ef66b244b148183665fe34b1ec1c771b to your computer and use it in GitHub Desktop.
PHP for loop with HTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
<style> | |
.row { | |
background-color: #f1f1f1; | |
height: 100vh; | |
} | |
.row .container { | |
max-width: 1000px; | |
margin: 5% auto; | |
display: flex; | |
flex-direction: row; | |
justify-content: center; | |
gap: 20px; | |
} | |
.row .container .box { | |
background-color: #333; | |
color:#fff; | |
width: 30%; | |
height: 80vh; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="row"> | |
<div class="container"> | |
<?php | |
for( $i=0; $i<3; $i++ ){ | |
echo '<div class="box">'.$i.'</div>'; | |
echo "<div class=\"box\">".$i."</div>"; | |
echo "<div class='box'>".$i."</div>"; | |
echo ' <a href="'.$url.'"></a>'; | |
} | |
?> | |
<?php for( $i=0; $i<3; $i++ ){ ?> | |
<div class="box"> | |
<?php echo $i; ?> | |
</div> | |
<?php } ?> | |
<?php // one more example ?> | |
<?php for( $i=1; $i<=3; $i++ ){ ?> | |
<div class="box"> | |
<img src="http://localhost/dynamicphp/assets/img/<?php echo $i; ?>.jpg" alt=""> | |
<?php echo $i; ?> | |
</div> | |
<?php } ?> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment