Issue
I have a code in codeigniter similar to this that works great.
<?php if (a>b) echo (a-b); else echo '0'; ?>
Problem is, I want to add compound functions. I've tried the code below, but it won't work. I receive an error code: "Parse error: syntax error, unexpected 'if' (T_IF)"
<?php echo (if (a>b) echo (a-b); else echo '0') + (if (c>d) echo (c-d); else echo '0') + (if (e>f) echo (e-f); else echo '0'); ?>
Solution
<?php echo ((a > b)?(a - b):0) + ((c > d)?(c - d):0) + ((e > f)?(e - f):0); ?>
Answered By - Roberto Raymon
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.