Reputation:
i am new in web development , im working now with Html and Php and i wanna know if there is a way i can display a text on a different number of times due to a variable , i have a variable $count
, so for example if $count = 1
i want it to display the text one time like this :
<h1> This is a Text 1 </h1>
And if $count = 3
i want it to be like this :
<h1> This is a Text 1 </h1>
<h1> This is a Text 2 </h1>
<h1> This is a Text 3 </h1>
I'll be so glad to have your help please
Upvotes: 0
Views: 67
Reputation: 561
You can do it as follows:
<?php
$count = 3;
for ($i = 0; $i < $count; $i++) {
?>
<h1>This is a Text</h1>
<?php
}
?>
Upvotes: 0
Reputation: 871
You can use a loop , like this :
<?php
for ($i = 0; $i <= count; $i++) {
echo "<h1> This is a Text ".$i." </h1>";
}
?>
Upvotes: 1