且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP函数返回字符串

更新时间:2022-11-11 10:12:06

您应该将返回值存储在一个变量中:

You should simply store the return value in a variable:

$deliveryPrice = getDeliveryPrice(12);
echo $deliveryPrice; // will print 20

$ deliveryPrice 上面的变量是函数内部的不同的变量,而不是 $ deliveryPrice 。由于变量范围,后者在函数外部不可见。

The $deliveryPrice variable above is a different variable than the $deliveryPrice inside the function. The latter is not visible outside the function because of variable scope.