Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // this function was added into helpers.php
- function getAmountColorStyle(float $amount): string
- {
- $color;
- if($amount < 0) {
- $color = 'red';
- } elseif ($amount > 0) {
- $color = 'green';
- } else {
- $color = '';
- }
- return $color;
- }
- // then in transactions.php file we add:
- <span style="color: <?php echo getAmountColorStyle($transaction['amount']) ?>;" >
- <?= formatDollarAmount($transaction['amount']) ?>
- </span>
- // This way, we only need to have one span where we put out $transaction['amount']
- // and it will be styled with color-based if the number is negative or positive
Add Comment
Please, Sign In to add comment