how can modify this script to add instead of increment.

Discussion in 'PHP' started by co.ador, Feb 10, 2010.

  1. #1
    <?php
      $aDoor = $_POST['formDoor'];
      if(empty($aDoor)) 
      {
        echo("You didn't select any buildings.");
      } 
      else 
      {
        $N = count($aDoor);
    
        echo("You selected $N door(s): ");
        for($i=0; $i < $N; $i++)
        {
          echo($aDoor[$i] . " ");
        }
      }
    ?>
    PHP:
    The script above will increment and then echo the extracted values of the variable array $aDoor, How can I modify to sum the values instead?
     
    co.ador, Feb 10, 2010 IP
  2. co.ador

    co.ador Peon

    Messages:
    120
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Found the solution thank you guys.

    <?php
      $aDoor = $_POST['formDoor'];
      if(empty($aDoor)) 
      {
        echo("You didn't select any buildings.");
      } 
      else 
      {
        $N = count($aDoor);
    
        echo("You selected $N door(s): ");
        for($i=0; $i < $N; $i++)
        {
          echo($aDoor[$i] . " ");
        }
    	echo "Sum of vlues = ".array_sum($aDoor);
      }
    ?>
    
    PHP:
     
    co.ador, Feb 10, 2010 IP