2017-12-05 4 views
-1
function countproduct(){ 
     $count = 0; 
     $cart = isset($_SESSION['cart']) ? $_SESSION['cart']:array(); 
     foreach($cart as $row): 
      if($row['qty']!=0){ 
       $count = $count + 1; 
      } 
     endforeach; 

     return $count; 

ich möchte wissen, was die Bedeutung von? nach dem isset ($ _ SESSION [ 'Warenkorb'])Was bedeutet "?" in dieser Aussage in php

+1

Lesen Sie über kurze IF-Syntax –

+1

[Ternary-Operator] (https://davidwalsh.name/php-ternary-examples) – Andrew

+0

kann ich einen Link haben –

Antwort

1

Es ist ein ternärer Operator, diese Linie: Sie php operations documentation überprüfen Weitere Informationen

if (isset($_SESSION['cart'])) { 
    $cart = $_SESSION['cart']; 
} else { 
    $cart = array(); 
} 

:

$cart = isset($_SESSION['cart']) ? $_SESSION['cart']:array(); 

Kann zu verwandeln