我的食谱应用程序有表格,可将配料插入数据库。如果尚未提交任何内容,则营养值显示为“0”。否则,它们会更新为帖子值。
我的营养展示结构是:
Calories:
<?php if ($ingredientArray[calorieKey] >= 1)
echo $ingredientArray[calorieKey];
else echo 0; ?><br />
Protein:
<?php if ($ingredientsArray[proteinKey] >= 1)
echo $ingredientArray[proteinKey];
else echo 0; ?><br />
...并继续进行大约 20 项。问题是:
仅使用 1 个 if/else 语句来重构代码以显示 2 种不同的形式(动态和静态)会更有效,还是按原样更好?