The*_*Kid 9 php string function
我是PHP的新手.我有一个检查价格成本的功能.我想从这个函数返回变量以便全局使用:
<?
function getDeliveryPrice($qew){
if ($qew=="1"){
$deliveryPrice="60";
} else {
$deliveryPrice="20";
}
return $deliveryPrice;
}
// Assuming these two next lines are on external pages..
getDeliveryPrice(12);
echo $deliveryPrice; // It should return 20
?>
Run Code Online (Sandbox Code Playgroud)
Jon*_*Jon 14
您只需将返回值存储在变量中:
$deliveryPrice = getDeliveryPrice(12);
echo $deliveryPrice; // will print 20
Run Code Online (Sandbox Code Playgroud)
$deliveryPrice上面的变量是与函数内部不同的变量$deliveryPrice.由于范围可变,后者在函数外部不可见.
| 归档时间: |
|
| 查看次数: |
50207 次 |
| 最近记录: |