-2

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
ngplayground
  • 20,365
  • 36
  • 94
  • 173

5 Answers5

5
'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
2

It sets S_DISPLAY_VEHICLE_OWNER with a shorthand notation of if/else.

if($owned == 'MODERATE' OR $owned == 'YES') {

    return 1

}else{

    return 0

}
Pieter
  • 1,823
  • 1
  • 12
  • 16
0

if $owned equals 'MODERATE' or 'YES' then the S_DISPLAY_VEHICLE_OWNER variable will be populated with 1 else 0

Nil'z
  • 7,487
  • 1
  • 18
  • 28
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.

apartridge
  • 1,790
  • 11
  • 18
0

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;
}
Expedito
  • 7,771
  • 5
  • 30
  • 43