title: Codility Invalid result type, int expected with PHP
body: <p>Could you tell why Codility tell me the next error, please?</p>
  
  <blockquote>
    <p>Running solution... Compilation successful.</p>
    
    <p>Example test:    [-1, 3, -4, 5, 1, -6, 2, 1]  Output (stderr): Invalid
    result type, int expected. RUNTIME ERROR  (tested program terminated
    unexpectedly) </p>
    
    <p>Detected some errors.</p>
  </blockquote>
  
  <p>My solution was wrote on PHP. </p>
  
  <pre><code>function solution($A) {
      $N = count($A);
      $Ps = array();
      foreach ( $A  as $KeyP =&gt; $P ) {
          $sum = 0;
          if ( $KeyP == 0 ) {                 
              for ( $x = 1; $x &lt; $N; $x++ ) {
                  $sum += $A[$x];
              }
              if ( $sum == $P ) {
                  $Ps[] = $KeyP;
              }
          }
          else {
              if ( ($KeyP+1) == $N ) {                
                  for ( $z = 0; $z &lt; $KeyP; $z++) :
                      $sum += $A[$z];
                  endfor;     
                  if ( ( $sum &gt;= 0 ) AND ( $sum  &lt; $N ) ) {
                      $Ps[] = $KeyP;
                  }   
              }           
              else {      
                  $sum1 = 0;
                  $sum2 = 0;          
                  for ( $z = 0; $z &lt; $KeyP; $z++ ) :
                      $sum1 += $A[$z];
                  endfor; 
                  for ( $y = ( $KeyP+1 ); $y &lt;= ($N-1); $y++ ) :
                      $sum2 += $A[$y];
                  endfor;                             
                  if ( $sum1 == $sum2 ) {
                      if ( $sum1 &lt; $N ) {
                          $Ps[] = $KeyP;
                      }
                  }
              }   
          }
      }
      return ( count($Ps) &lt;= 0 ) ? -1: $Ps;
  }
  </code></pre>
  
  <p>The output of my function given the next array has been:</p>
  
  <pre><code>array(-1, 3, -4, 5, 1, -6, 2, 1);
  </code></pre>
  
  <p>Ouput</p>
  
  <blockquote>
    <p>Array ( [0] => 1 [1] => 3 [2] => 7 )</p>
  </blockquote>
  
  <p>It's just like they request me in the task but Codility show me all those errors.</p>
  
  <p>The demo task is below:</p>
  
  <blockquote>
    <p>This is a demo task.</p>
    
    <p>A zero-indexed array A consisting of N integers is given. An
    equilibrium index of this array is any integer P such that 0 ≤ P &lt; N
    and the sum of elements of lower indices is equal to the sum of
    elements of higher indices, i.e.  A[0] + A[1] + ... + A[P−1] = A[P+1]
    + ... + A[N−2] + A[N−1]. Sum of zero elements is assumed to be equal to 0. This can happen if P = 0 or if P = N−1.</p>
    
    <p>For example, consider the following array A consisting of N = 8
    elements:</p>
  
  <pre><code>A[0] =&gt; -1   
  A[1] =&gt;  3 
  A[2] =&gt; -4   
  A[3] =&gt;  5   
  A[4] =&gt;  1   
  A[5] =&gt; -6   
  A[6] =&gt;  2   
  A[7] =&gt;  1
  </code></pre>
    
    <p>P = 1 is an equilibrium index of this array, because:</p>
    
    <p>A[0] = −1 = A[2] + A[3] + A[4] + A[5] + A[6] + A[7] P = 3 is an
    equilibrium index of this array, because:</p>
    
    <p>A[0] + A[1] + A[2] = −2 = A[4] + A[5] + A[6] + A[7] P = 7 is also an
    equilibrium index, because:</p>
    
    <p>A[0] + A[1] + A[2] + A[3] + A[4] + A[5] + A[6] = 0 and there are no
    elements with indices greater than 7.</p>
    
    <p>P = 8 is not an equilibrium index, because it does not fulfill the
    condition 0 ≤ P &lt; N.</p>
    
    <p>Write a function:</p>
    
    <p>function solution($A);</p>
    
    <p>that, given a zero-indexed array A consisting of N integers, returns
    any of its equilibrium indices. The function should return −1 if no
    equilibrium index exists.</p>
    
    <p>For example, given array A shown above, the function may return 1, 3
    or 7, as explained above.</p>
    
    <p>Assume that:</p>
    
    <p>N is an integer within the range [0..100,000]; each element of array A
    is an integer within the range [−2,147,483,648..2,147,483,647].
    Complexity:</p>
    
    <p>expected worst-case time complexity is O(N); expected worst-case space
    complexity is O(N), beyond input storage (not counting the storage
    required for input arguments). Elements of input arrays can be
    modified.</p>
  </blockquote>
  
  <p>Thank you.</p>