-3

我正在尝试$totalPrice从下面的数组中分配一个值,但它只返回 0,回显$totalPrice在某些 HTML 代码中,如果我使用 echo $sites[$site][0] 它会显示该值,但在分配时不显示到$totalPrice

$totalPrice = 0;
$site = "UM";

$totalPrice = $sites[$site][0];


    $sites = array
    (
        "US" => array (38.78, 11, 5.5),
        "UM" => array (44.55, 11, 5.5),
        "PS" => array (55.28, 11, 5.5),
        "PM" => array (66.55, 11, 5.5)
    )

    echo $totalPrice; 
4

2 回答 2

2

您可以尝试此代码..您需要声明$totalPrice以下数组值...

$totalPrice = 0;
$site = "UM";


    $sites = array(
        "US" => array (38.78, 11, 5.5),
        "UM" => array (44.55, 11, 5.5),
        "PS" => array (55.28, 11, 5.5),
        "PM" => array (66.55, 11, 5.5)
    );

    $totalPrice = $sites[$site][0];
echo $totalPrice;
于 2018-05-24T11:16:37.713 回答
2
$totalPrice = 0;
$site = "UM";

$sites = array
(
    "US" => array (38.78, 11, 5.5),
    "UM" => array (44.55, 11, 5.5),
    "PS" => array (55.28, 11, 5.5),
    "PM" => array (66.55, 11, 5.5)
);
$totalPrice = $sites[$site][0];


echo $totalPrice; 

您在初始化之前使用了$totalPrice = $sites[$site][0];变量$sites,这就是为什么它每次都给您答案 0。

于 2018-05-24T11:15:16.660 回答