how to use if condition in array variables? |
How to use if condition in array
Code: $insert = array();
(04-24-2019, 10:58 PM)kvanaraj Wrote: How to use if condition in array The key point that @Wouter60 makes (but does not explain) is that you assign a value of 1 to $certid, e.g. $certid=1. But what you really wanted to do was test for equality, e.g. $certid==1. What you should have written was PHP Code: 'amt' => if($certid==1,8500 else 300 , Wouter60 writes it more concisely by using a ternary statement instead of an "if/else" statement PHP Code: 'amt' => $certid==1 ? 8500 : 300 , Quote:The key point that @Wouter60 makes (but does not explain) is that you assign a value of 1 to $certid Actually that wasn't my key point. The syntax PHP Code: 'amt' => if($certid=1,8500 else 300 , The syntax I suggested is: Quote:<condition> ? <value1> : <value2> This is a very userful one-line operation, in human language: if <condition> is true, then return value1, else return value 2.
(04-26-2019, 07:09 AM)Wouter60 Wrote: The syntax Yeah. Well. There is that. ![]() Forgive me for trying to add an explanation to your terse (and entirely correct) reply. ![]() |
Welcome Guest, Not a member yet? Register Sign In |