PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 8, 2022

[FIXED] Adding and subtracting multiple if-else statements in CodeIgniter

 February 08, 2022     codeigniter, php     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing