If you do not take all this into the function, then the result works. And if this is how to perform everything in the function, then PHP swears:
"Invalid argument supplied for foreach ()"
I concluded that I am incorrectly passing an array as an argument for my user-defined function resultBuyList() :
$buyList = array( array('name' => 'Телевизор', 'price' => '400', 'quantity' => 1), array('name' => 'Телефон', 'price' => '300', 'quantity' => 3), array('name' => 'Кросовки', 'price' => '150', 'quantity' => 2), ); function resultBuyList($buyList) { foreach ($buyList as $key => $value) { $credits = $value['quantity'] * $value['price']; $creditCount += $credits; $productCount += $value['quantity']; } return $result = "Вы купили $productCount единиц товара, общая сумма к оплате: $creditCount"; } resultBuyList($buyList);
foreachin such a message swears on it usually.А если вот так в функции все выполнять, тогда PHP ругается- so how is it? It is better to completely write as you try to write ... exactly as when swearing - Aleksey Shimansky