“?”的含义是什么?在 php 的声明中

What is the meaning of the "?" in this statement in php

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;

我想知道是什么意思?在 isset($_SESSION['cart'])

之后

这是一个三元运算符,这些行:

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

可以转化为:

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

更多信息您可以查看php operations documentation