Lets see if I can describe this right.
OK, you've got a 2d array as follows:
$cart[123]['qty']=5;
$cart[123]['sku']=123;
$cart[123]['name']='tanning lotion';
$cart[123]['price']=4.50;
$cart[124]['qty']=1;
$cart[124]['sku']=124;
$cart[124]['name']='baby oil';
$cart[124]['price']=2.50;
(yes, this is a shopping cart related question but could just as well apply to chess problems or other things :-)
Hey, I KNOW I can do a nested foreach() loop and get the prices and sum them up. But is there any way to sum up the prices through the SECOND dimension, kind of like:
sum_of($cart[*]['price']);
On a spreadsheet, this would be like shooting an arrow down the column named "price" and summing things up, without condsidering the rows or their names.
PHP has powerful arrays but is there any way to do this? Seems someone would have bumped up against this.