2016-01-27 47 views
-1

我有一个需要击中的用户的目标,并且该用户通过了我希望它显示不同颜色的目标。所以现在我有目标所需的全部目标* time_spent/day_length。如何跟踪目标点数?

例如,如果目标是10,用户得到11分,我希望它显示不同的颜色,因为他通过了目标。我如何获得结果以显示通过的目标?

我在想这样的事情

$color_performace = function($value, $goal) { 
    if($value < $goal) 
     return 'notenough'; 
    elseif($value >$goal) 
     return 'awesome'; 
    else 
     return 'enough'; 
}; 

和功能

$total_goals_class = $color_performance($total_goals,round($goals_needed*$goal_multiplier)); 
+0

更新后的代码... – Ris

回答

1

目前尚不清楚你到底是什么后,但如果你要处理得到的东西在页面上改变颜色您将需要输出html & css。

因此,也许有类似:

$color_performace = function($value, $goal) { 
    if($value < $goal) 
     return '<p style="color: red;">notenough</p>'; 
    elseif($value >$goal) 
     return '<p style="color: green;">awesome</p>'; 
    else 
     return '<p style="color: yellow;">enough</p>'; 
}; 

这是一个快速和肮脏的例子来说明这个概念,我可能会改变它使用类和有CSS在主文件中设置某个地方,并使用十六进制代码的颜色。