Home > Net >  Display font awesome icons in php if clause
Display font awesome icons in php if clause

Time:03-23

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.

CodePudding user response:

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 ></i>';   
}
else{
 echo '<i ></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 ></i>'  : '<i ></i>';
?>

As you can see the second option is cleaner, but it can get messy with longer expressions so beware.

  • Related