What does this piece of PHP actually mean and how could it be displayed differently?
'S_DISPLAY_VEHICLE_OWNER' => ($owned == 'MODERATE' || $owned == 'YES') ? 1 : 0
What does this piece of PHP actually mean and how could it be displayed differently?
'S_DISPLAY_VEHICLE_OWNER' => ($owned == 'MODERATE' || $owned == 'YES') ? 1 : 0
'S_DISPLAY_VEHICLE_OWNER' => ($owned == 'MODERATE' || $owned == 'YES') ? 1 : 0
another look:
if ($owned == 'MODERATE' || $owned == 'YES'){
$result = 1;
}else{
$result = 0;
}
'S_DISPLAY_VEHICLE_OWNER' => $result
It sets S_DISPLAY_VEHICLE_OWNER
with a shorthand notation of if/else.
if($owned == 'MODERATE' OR $owned == 'YES') {
return 1
}else{
return 0
}
if $owned equals 'MODERATE' or 'YES' then the S_DISPLAY_VEHICLE_OWNER
variable will be populated with 1 else 0
Basically in plaintext the expression ($owned == 'MODERATE' || $owned == 'YES') ? 1 : 0
means
if owned is moderate or owned is yes then 1 else 0
The field S_DISPLAY_VEHICLE_OWNER
in your array is set to 1
or 0
depending on
the value of $owned.
It's assigning a value of 1 or 0 to an associative array if the value of $owned
is either "MODERATE" or "YES." So, if the array were $arr
, then it could be rewritten as:
if ($owned == 'MODERATE' || $owned == 'YES'){
$arr['S_DISPLAY_VEHICLE_OWNER'] = 1;
} else {
$arr['S_DISPLAY_VEHICLE_OWNER'] = 0;
}