PHP Function to return string

后端 未结 4 1873
天涯浪人
天涯浪人 2021-01-11 19:36

I am fairly new to PHP. I have a function which checks the cost of price. I want to return the variable from this function to be used globally:



        
4条回答
  •  孤城傲影
    2021-01-11 20:01

    You should simply store the return value in a variable:

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

    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.

提交回复
热议问题