gpt4 book ai didi

javascript - PHP传递参数给新的字符串(学习)

转载 作者:行者123 更新时间:2023-11-30 12:16:56 27 4
gpt4 key购买 nike

还在学习,还有很多问题,所以这里有一些。我正在进行 javascript -> PHP 转换,并希望确保这些做法是正确的。是$dailyparams->$calories = $calories;一条正确的线?再次感谢!

JavaScript

DailyParams.create4 = function(/*double*/ calories, /*double*/ carbpercent, /*double*/ sodium, /*double*/ actparam) {
if (calories < 0.0) calories = 0.0;
if (carbpercent < 0.0) carbpercent = 0.0;
if (carbpercent > 100.0) carbpercent = 100.0;
if (sodium < 0.0) sodium = 0.0;
if (actparam < 0.0) actparam = 0.0;

var dailyparams = new DailyParams();
dailyparams.calories = calories;
dailyparams.carbpercent = carbpercent;
dailyparams.sodium = sodium;
dailyparams.actparam = actparam;

return dailyparams;}
DailyParams.create2 = function(/*Intervention*/ inter, /*Baseline*/ base) {
var dailyparams = new DailyParams();
dailyparams.calories = inter.getcalories();
dailyparams.carbpercent = inter.getcarbinpercent();
dailyparams.sodium = inter.getsodium();
dailyparams.actparam = inter.getAct(base);

return dailyparams;

PHP

public function create4($calories, $carbpercent, $sodium, $actparam) {
if ($calories < 0.0) $calories = 0.0;
if ($carbpercent < 0.0) $carbpercent = 0.0;
if ($carbpercent > 100.0) $carbpercent = 0.0;
if ($sodium < 0.0) $sodium = 0.0;
if ($actparam < 0.0) $actparam = 0.0;

$dailyparams = new $DailyParams();
$dailyparams->$calories = $calories;
$dailyparams->$carbpercent = $carbpercent;
$dailyparams->$sodium = $sodium;
$dailyparams->$actparam = $actparam;

return $dailyparams;
}
public function create2($inter,$base) {
$dailyparams = new $DailyParams();
$dailyparams->$calories = $inter->getcalories();
$dailyparams->$carbpercent = $inter->getcarbinpercent();
$dailyparams->$sodium = $inter->getsodium();
$dailyparams->$actparam = $inter->getAct($base);

return $dailyparams;
}

最佳答案

DailyParams 是类名,去掉$:

$dailyparams = new DailyParams();

calories 等属性名称相同:

$dailyparams->calories = $calories;

关于javascript - PHP传递参数给新的字符串(学习),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32193479/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com