lists.zerezo.com
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
***BOGO*** Re: [PHP] Summing array indexes.
- Date: Fri, 5 Sep 2008 01:43:01 +0100
- From: "Diogo Neves" <dafneves@xxxxxxxxx>
- Subject: ***BOGO*** Re: [PHP] Summing array indexes.
On Thu, Sep 4, 2008 at 11:02 PM, Tom Shaw <php.coder@xxxxxxxxx> wrote:
> Is there an easy way to loop thru the array below and add the incremented
> total price indexes so the order_total_price index contains the correct
> sum.
> Any help would be greatly appreciated.
>
>
>
>
>
> array(5) {
>
> [0] => array(15) {
>
> ["order_date"] => string(8) "09-01-08"
>
> ["order_product_price_1"] => string(5) "10.00"
>
> ["order_product_price_2"] => string(5) "20.00"
>
> ["order_total_price"] => string(0) ""
>
> }
>
> [1] => array(19) {
>
> ["order_date"] => string(8) "09-01-08"
>
> ["order_product_price_1"] => string(5) "25.00"
>
> ["order_product_price_2"] => string(5) "15.00"
>
> ["order_total_price"] => string(0) ""
>
> }
>
>
>
> Like this.
>
>
>
> array(5) {
>
> [0] => array(15) {
>
> ["order_date"] => string(8) "09-01-08"
>
> ["order_product_price_1"] => string(5) "10.00"
>
> ["order_product_price_2"] => string(5) "20.00"
>
> ["order_total_price"] => string(0) "30.00"
>
> }
>
> [1] => array(19) {
>
> ["order_date"] => string(8) "09-01-08"
>
> ["order_product_price_1"] => string(5) "25.00"
>
> ["order_product_price_2"] => string(5) "15.00"
>
> ["order_total_price"] => string(0) "40.00"
>
> }
>
>
>
> Tom Shaw
>
>
>
> php.coder@xxxxxxxxx
>
>
>
> foreach( $arr_top as $arr_top_elem ) {
$total = 0;
foreach( $arr_top_elem as $key => $elem ) {
if ( strpos( 'order_product_price_' ) === 0 ) {
$total += $elem;
}
}
$arr_top_elem['order_total_price'] = $total;
}
This should do da trick...
--
Thanks,
Diogo Neves
Web Developer @ SAPO.pt by PrimeIT.pt