我有一个这样的 PHP 函数:
function count_nutrient_value($input){
// some difficult operations here
return $output; // this is a string
}
我正在使用这样的(示例):
$print .= 'This nutrient is giving you '.count_nutrient_value(40).' percent.';
现在的问题是,从函数中,我需要返回另一个值 - 一个数字是上升还是下降的信息。所以我改变了功能:
function count_nutrient_value_new($input){
// some difficult operations here
return array($output,$status); // this is an array, obviously
}
但是现在我不能那么容易地使用该功能,因为我不能再这样做了:
$print .= 'This nutrient is giving you '.count_nutrient_value_new(40).' percent.';
但相反,我需要将其扩展到更多行,如下所示:
$return = count_nutrient_value_new(40);
$print .= 'This nutrient is giving you '.$return[0].' percent.';
这种情况有解决办法吗?这将是:
A)不从函数返回数组(但以其他方式解决问题)
B)返回数组并在代码中找到使用该函数的更简单方法
C)其他?