Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 两个属性相乘_Php - Fatal编程技术网

Php 两个属性相乘

Php 两个属性相乘,php,Php,我需要弄清楚如何计算工人的周薪。我需要使用GetWeekldAgensions方法来实现这一点,但无法计算如何将工资和工时这两个属性相乘 我的问题是class.php中的代码是什么,以及如何在对象中调用它。任何建议都会令人惊讶,谢谢 附件将是我的代码到目前为止 像什么手帕-웃-panky在上面说过,但将函数公开 public function getWeeklyEarnings() { return $this->hours * $this->wage; } 这样,您可以在

我需要弄清楚如何计算工人的周薪。我需要使用GetWeekldAgensions方法来实现这一点,但无法计算如何将工资和工时这两个属性相乘

我的问题是class.php中的代码是什么,以及如何在对象中调用它。任何建议都会令人惊讶,谢谢


附件将是我的代码到目前为止

像什么手帕-웃-panky在上面说过,但将函数公开

public function getWeeklyEarnings()
{
    return $this->hours * $this->wage;
}
这样,您可以在提供的代码中调用它,如:

echo "Weekly Earnings: $" . $w1->getWeeklyEarnings();
或者,如果您无法编辑
hourly_worker.class.php
,但可以访问该类的工时和工资,那么您可能可以执行以下操作:

echo "Weekly Earnings: $" . $w1->hours * $w1->wage;

请发布实际代码而不是截图。详情请参阅。非常感谢。