Issue
I want to display font awesome icons depending on a condition of two php variable. For example
if($a > $b) display an arrow up icon else an arrow down icon.
Thanks in advance.
Solution
In my opinion there's 2 ways to implement this, i don't know what the implementation is for. But in its most simple form it would look like this:
<?php
$a = 1;
$b = 0;
if($a > $b){
echo '<i class="fa-solid fa-arrow-down"></i>';
}
else{
echo '<i class="fa-solid fa-arrow-up"></i>';
}
?>
You could also do it in 1 line this is called a Ternary Expression, this is useually done with simple if statement, to make the code look cleaner.
<?php
$a = 1;
$b = 0;
echo $a > $b ? '<i class="fa-solid fa-arrow-down"></i>' : '<i class="fa-solid fa-arrow-up"></i>';
?>
As you can see the second option is cleaner, but it can get messy with longer expressions so beware.
Answered By - Kevin_Vink
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.