Totally lost here. The output of one record in the array is posted below. I would like to get the sum of all the records in field [5] of the [Transporter Log].

I have tried various variations of the following (which I cut/paste from another thread). $subtotal allows returns '0'. I'm thinking I need to do nested loops to reach the [Transporter Log] array but not sure how to accomplish that. Any guidance would be much appreciated.

$item = $datac; //results of mysql query
        foreach($item as $key => $val){
            $data[$key] = explode(",", $val);
        }
        for($k = 1; $k < count($item); $k++){
            $subtotal[$k] = substr($data[$k][4],2);
        }
        foreach($subtotal as $val)
          echo $val.' ';
          
        echo '<br>Newest Sum: '.(array_sum($subtotal));

Here's the output of the first record in the array:

Array
(
    [0] => Array
        (
            [Transporter Log] => Array
                (
                    [10] => Array
                        (
                            [2] => Array
                                (
                                    [0] => 2007-07-10
                                )

                            [4] => Array
                                (
                                    [0] => 1
                                )

                            [5] => Array
                                (
                                    [0] => 1
                                )

                            [6] => Array
                                (
                                    [0] => Shelter Wildlife Delivery
                                )

                            [17] => Array
                                (
                                    [0] => 
                                )

                            [25] => Array
                                (
                                    [0] => 
                                )

                            [uid] => 1
                            [mod_date] => 2007-07-26
                            [proxyid] => 1
                            [creation_date] => 2007-07-26
                            [creator_email] => admin@mydomain.com
                        )

                )

        )
Member Avatar for iamthwee

Start of by breaking your problem into smaller chunks.

First find out if it is doing the very first bit, then the second third etc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.