title: Sum only values 1 from array
body: <p>I have array with variables from $qA01_1 up to $qA30_5 (150 variables). Some of the variables can have value 0 or 1 or 5 (example $qA21_3 = 0 or 1 or 5). And I would like to know how to make sum of all variables which have value 1. </p>
  
  <p>Here part of array</p>
  
  <pre><code>$qA01_1 = $_SESSION['qA01_1']; // example: $qA01_01 can have value 0 or 1 or 5, like other variables  
  $qA01_2 = $_SESSION['qA01_2']; // $qA01_02 = 0 or 1 or 5
  $qA01_3 = $_SESSION['qA01_3']; // $qA01_03 = 0 or 1 or 5
  $qA01_4 = $_SESSION['qA01_4']; // $qA01_04 = 0 or 1 or 5
  $qA01_5 = $_SESSION['qA01_5']; // $qA01_05 = 0 or 1 or 5
  
  $qA02_1 = $_SESSION['qA02_1']; // $qA02_01 = 0 or 1 or 5   
  $qA02_2 = $_SESSION['qA02_2']; // $qA02_02 = 0 or 1 or 5
  $qA02_3 = $_SESSION['qA02_3']; // $qA02_03 = 0 or 1 or 5
  $qA02_4 = $_SESSION['qA02_4']; // $qA02_04 = 0 or 1 or 5
  $qA02_5 = $_SESSION['qA02_5']; // $qA02_05 = 0 or 1 or 5
  
  // up to...
  
  $qA30_1 = $_SESSION['qA30_1']; // $qA30_01 = 0 or 1 or 5    
  $qA30_2 = $_SESSION['qA30_2']; // $qA30_02 = 0 or 1 or 5
  $qA30_3 = $_SESSION['qA30_3']; // $qA30_03 = 0 or 1 or 5
  $qA30_4 = $_SESSION['qA30_4']; // $qA30_04 = 0 or 1 or 5
  $qA30_5 = $_SESSION['qA30_5']; // $qA30_05 = 0 or 1 or 5
  </code></pre>
  
  <p>Here is proposal but not work. I´m begginer, please for help.</p>
  
  <pre><code>$values = [];
  for($i=1;$i&lt;=30;$i++)
  {
      foreach([1,2,3,4,5] as $index) 
      {
          if(${'qA'.str_pad($i, 2, "0", STR_PAD_LEFT).'_'.$index} == 1) 
          {
              $values[] = ${'qA'.str_pad($i, 2, "0", STR_PAD_LEFT).'_'.$index};
          }
      }
  } 
  echo $values;
  </code></pre>