Welcome Guest, Not a member yet? Register   Sign In
how to use if condition in array variables?
#3

(04-24-2019, 10:58 PM)kvanaraj Wrote: How to use if condition in array
Code:
$insert = array();
       $insert[] = array(
        'appno' => $appno,
        'regno' => $regno,
          'certid' => $certid,
             'amt' => if($certid=1,8500 else 300 ,
             'date' => $today
               );      

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==8500 300 
Reply


Messages In This Thread
RE: how to use if condition in array variables? - by dave friend - 04-25-2019, 09:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB