Search code examples
phpmysqllaravelcodeigniter

multiple value (or) in php variable is possible?


is possible multiple value in php variable with condition (or). such as like this

$shippingCost = $selectedShipping['cost'] || null;

I've tried but it gives return error

result


Solution

  • We use ternary operators to assign values to parameter when there are conditions to check. otherwise you can simply use if else conditions as well

    using ternary operator 
    
    $shippingCost = isset($selectedShipping['cost']) ? $selectedShipping['cost'] : null
    
    
    using if,else
    
    $shippingCost = 0;
    if(isset($selectedShipping['cost'])){
      $shippingCost = $selectedShipping['cost'];
    }