I want to use $i into his PHP condition how can I do this? I have no idea how to echo into condition. plz see the code and if you can plz help me. thank you advanced.
<?php
for($i=1; $i<4; $i++) {
if($top_h_text_**I want to use $i here!**) {
?>
<li>
<?php
if($top_h_icon_**I want to use $i here!**) {
?>
<i class="<?php echo $top_h_icon_**I want to use $i here!**;?>"></i>
<?php
}
if($top_h_icon_**I want to use $i here!** == 'fa fa-envelope'){
?>
<a href="mailto:<?php echo $top_h_text_**I want to use $i here!**;?>"><span class="top_header_text"><?php echo $top_h_text_**I want to use $i here!**;?></span></a>
<?php
} else {
?>
<span class="top_header_text"><?php echo $top_h_text_**I want to use $i here!**;?></span>
<?php
}
?>
</li>
<?php
}
}
?>
2
Answers
To accomplish what you are trying to do, simply follow this example:
becomes
So you basically take the string you want (which should be the name of an existing variable) and wrap it with ${}
If this is in fact WordPress, and your
top_h_icon_
andtop_h_text
are in fact defined. This would be appropriate method for concatenation of your$i
increment and the variables. This is how you join two parts to make a single string.Note that with WordPress and outputting dynamic variables, you should escape them.