Mám problém s PHP, potrebujem získať súčin hodnôt v poli.
Pole vyzera asi takto.
Kód: Vybrat vše
array(1) { [0]=> float(110.5) } array(1) { [0]=> float(12.9) }
Potrebuj spočítať 110.5 a 12.9 funkciou array_sum.
Problém je ale ten že mi to vypisuje chybu.
Kód: Vybrat vše
PHP Notice: Undefined offset: 1 in ...\htdocs\app\View\cart.phtml:24
2×
PHP Warning: array_sum() expects parameter 1 to be array, null given in ...\htdocs\app\View\cart.phtml:24
Podľa chyby asi nemám kľúč/parameter ale vôbec si neviem dať rady.
Kód:
Kód: Vybrat vše
<?php
$results = DatabaseTool::fetchAll('SELECT * FROM `cart` WHERE `owner`=:owner', array(':owner' => USER_SESSION));
?>
<?php foreach ($results as $result) : ?>
<tr>
<td><?=$result['id'];?></td>
<td><?=$result['nameproduct'];?></td>
<td><?=$result['price'];?> €</td>
<td><?=$result['quantity'];?></td>
</tr>
<?php
$s = array($result["price"]);
var_dump($s);
echo array_sum($s);
endforeach
?>
Môže mi niekto prosím s tým pomôcť?