如何将函数输出转换为float(php)类型的变量以进行进一步的数学运算?

如何将函数输出转换为float(php)类型的变量以进行进一步的数学运算?,php,function,variables,types,Php,Function,Variables,Types,你好,php开发人员,请帮助初学者 -我衷心感谢您的帮助 功能代码: 输出:var\u转储($float); 浮动(1.20383) 我的代码: 输出 如何从函数求和?我找到了答案返回$fin $data = curl_exec($ch); // get info about the request $info = curl_getinfo($ch); // close curl resource to free up system resources curl_close($ch); $arr

你好,php开发人员,请帮助初学者 -我衷心感谢您的帮助

功能代码:

输出:
var\u转储($float);
浮动(1.20383)

我的代码:

输出


如何从函数求和?我找到了答案
返回$fin

$data = curl_exec($ch);
// get info about the request
$info = curl_getinfo($ch);
// close curl resource to free up system resources
curl_close($ch);
$arr = json_decode($data,true);
$c = array_map( function ($in){
    return  $in['ask']['c'];
}, $arr['candles']);
sort($c);
//echo 'Min is: '.current($c)."\n";
$fin = end($c);
return $fin;
获取函数并计算

    function pivoty()
{
    $val = floatval(get_min_price());
    $sum = $val + $val;
    var_dump($sum);
}

输出:
float(2.40766)

1.20383
在您的输出中,因此看起来它正在执行您想要的操作。您显示的其他输出显示它们是浮点(或双精度)数据类型。是否还需要其他内容?如果希望函数更改为返回浮点,请将函数的代码添加到问题中。您还可以强制转换为数据类型,如
$float=(float)$min
如果它是float,我可以从数学上把它总结成另一个变量
echo$test\u float+$float;输出:1.1
@james I so也尝试过,但没有帮助$float=1.20383$试验浮点数=1.1;变量转储(gettype($float),gettype($test_float))
double
double
$total=$float+$test\U float;变量转储(gettype($total))<代码>双重
var_dump($total)<代码>2.3038
float(1.20383)
float(0)
float(0)
$data = curl_exec($ch);
// get info about the request
$info = curl_getinfo($ch);
// close curl resource to free up system resources
curl_close($ch);
$arr = json_decode($data,true);
$c = array_map( function ($in){
    return  $in['ask']['c'];
}, $arr['candles']);
sort($c);
//echo 'Min is: '.current($c)."\n";
$fin = end($c);
return $fin;
    function pivoty()
{
    $val = floatval(get_min_price());
    $sum = $val + $val;
    var_dump($sum);
}