PHP表格简单数学

时间:2016-11-22 12:19:22

标签: php mysql

我有一个名为$row['seuil_pil']的表,其中只包含数字。我希望将这些数字增加一定数量,但它不起作用。

这是我的代码:

$roof=0.12;      

$seuil_haut= array_product(($row['seuil_pil']*$roof) + $row['seuil_pil']); 

$seuil_haut= array(($row['seuil_pil']*$roof) + $row['seuil_pil']); 

$seuil_haut= ($row['seuil_pil']*$roof) + $row['seuil_pil'];  

foreach ($row['seuil_pil'] as $seuil_haut[])
{
    $seuil_haut[] = ($roof * $row['seuil_pil'] + $row['seuil_pil'] ); 
}

2 个答案:

答案 0 :(得分:3)

如果要将操作应用于您要迭代的数组,则必须使用带有引用的 foreach(var item in collection){ Classname obj = new Classname(); obj1.updatefirstvalue = item.something; obj1.updatesecondvalue = item.something; db.Entry(obj).State = EntityState.Modified; } db.SaveChanges();

foreach

答案 1 :(得分:1)

使用for - 循环:

$roof = 0.12;

$row['seuil_pil'] = array(4,1,3);

for($i = 0; $i < count($row['seuil_pil']); $i++) {
    $row['seuil_pil'][$i] *= (1 + $roof);
} 

var_dump($row['seuil_pil']);

//results in:
//array(3) { [0]=> float(4.48) [1]=> float(1.12) [2]=> float(3.36) }