Ad
Display Font Awesome Icons In Php If Clause
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.
Ad
Answer
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.
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad