如何在同一个PHP页面中对多个调用使用PHP函数?

问题描述 投票:0回答:1

我正在尝试使用php函数在订单状态页面上获取tola(11.664克)的价格。该函数使用php页面“ priceApi4CurCtrl.php”,该页面使用外部API从网站获取价格数据。我的功能如下:

function tolaPrice($cur_pick) {
    require('priceApi4CurCtrl.php');


    if($cur_pick == 'pkr') {

   $tola_price = $bitprice_pkr*10*11.664;
   return $tola_price;

}elseif($cur_pick == 'usd') {
   $tola_price = $bitprice_usd*10*11.64;
   return $tola_price;

}elseif($cur_pick == 'aed') {

    $tola_price = $bitprice_aed*10*11.64;
    return $tola_price;
}
}



$cur_pick = 'pkr';

echo tolaPrice($cur_pick);

该函数在使用echo tolaPrice($ cur_pick)的第一次调用时效果很好。但是,它无法完成所有后续调用,因此我无法完成第二个及后续订单的订单状态。

我不确定如何解决此问题。任何帮助将不胜感激。

php function
1个回答
0
投票

使用require_once

function tolaPrice($cur_pick) {
    require_once('priceApi4CurCtrl.php');
    ...
}

require_once语句与require相同,除了PHP将检查文件是否已包含,如果不包含,则不要再次包含(要求)它。

© www.soinside.com 2019 - 2024. All rights reserved.