A solution of the problem associated with functions and arrays?

Good day, please help to solve the problem in php:
You must create a function with any name, with one parameter - the array of items in the basket.
The function should count and return how many in the basket of goods (in one position of the basket can contain multiple items - field quantity).
The function will pass an array with the following structure:
$basket = [
[
'position' => 'php book',
'quantity' => 1,
],
[
'position' => 'wireless Mouse',
'quantity' => 12,
]
];

The number of items in the basket can be from 0 to 10
Thus, for solving the problem are prohibited to use other functions, anonymous functions, type conversions, classes, global variables.
April 19th 20 at 12:47
2 answers
April 19th 20 at 12:49
Use the loop foreach. With him you don't need any of that.
April 19th 20 at 12:51
<?php

function total($array = []): int {
 $total = 0;
 foreach ($array as &$value) {
 $total += $value['quantity'];
}
 return $total;
}

echo total([
[
 'position' => 'php book',
 'quantity' => 1,
],
[
 'position' => 'wireless Mouse',
 'quantity' => 12,
]
]);
why should be passed by reference - aniyah.Wolf67 commented on April 19th 20 at 12:54
@aniyah.Wolf67, I example with docks copied, and without a pointer - Mariela.Nicolas commented on April 19th 20 at 12:57
No docks, no way, very complicated code? - aniyah.Wolf67 commented on April 19th 20 at 13:00
@aniyah.Wolf67, writing by hand in php it is considered that the hands in the shit to drop. I'm on my fucking? - Mariela.Nicolas commented on April 19th 20 at 13:03

Find more questions by tags PHP