I have a foreach loop:

foreach($_SESSION as $key => $val)
{ etc....

Then at the end i have a variable $dave which holds an integer value.

$dave = number_format($dave,2);
echo "<b>€".$dave."</b> ".$valuenumber."<br />\n"; }

The problem is the variable $dave changes for each loop. I'm looking to get a total of all the $dave's at the end. Does anyone have an idea how I'd do that? Does the variable name have to be changed each time or something?

    Put it into an array... Before the loop, put:

    $dave = array();

    Then in the loop, do this:
    $dave[] = number_format($dave,2);

    Then do a count on the array to get the total.

      thanks for the reply.

      How would I do a count on the array?

        Hi,

        wouldn't return a count on the array just the number of records found ?

        To get a total I'd suggest to add something like

        $total = 0;

        in front of the loop and inside the loop

        $total += $dave;

        (or $total += $dave*$valuenumber; if valuenumber stands for valuenumber times dave)

        After the loop:

        $total = number_format($total,2);

        Or did I misunderstand something ?

        Thomas

          I am shooting from the hip myself here... I am usually the one who misses something LOL 😃 I guess we'll have to wait to hear back from denhamd2 to find out...

            Hi TheDefender,

            you're right 😃

            His post wasn't absolutely clear in this point 🙂

            Thomas

              thats fantastic ur code did exactly what i wanted tsinka, thanks

                Write a Reply...