次のような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) その他?