0

I am very very novice when it comes to PHP , but slowly learning :) I have a function that returns me an stdClass object with multiple arrays (see excerpt below).

I would like to iterate through it with a foreach loop and do some calcultations with certain values. Can anybody point me in the good direction ?

** Excerpt output print_r $result **

stdClass Object
(
    [processor] => stdClass Object
        (
            [code] => 0
            [message] => OK
            [rid] => 289411
            [testmode] => 1
        )

    [handler] => stdClass Object
        (
            [statistics] => Array
                (
                    [0] => Array
                        (
                            [eventdate] => data
                            [eventstatus] => data
                            [programid] => data
                            [programname] => data
                            [eventcurrency] => data
                            [clicks] => data
                        )
                    [1] => Array
                        (
                            [eventdate] => data
                            [eventstatus] => data
                            [programid] => data
                            [programname] => data
                            [eventcurrency] => data
                            [clicks] => data
                        )

                        )




                    )

What I would like to do for example is add up all the [clicks] values and then print the sum of all the [clicks]values.

Thank you very much in advance !

Bram
  • 11
  • 1
  • 2

1 Answers1

1

Try this:

$clicks = 0;
foreach($result->handler->statistics as $arrData){
    //calc like this
    $clicks += $arrData['clicks'];
}
echo "Clicks: " . $clicks;
Andre
  • 170
  • 6
  • Andre, thank you so very much !!! I know it was a simple question, but just learning , so really appreciated the help ! it works – Bram Dec 18 '12 at 13:19