title: What is the reason of returning -1 instead of lets say 0 at the end of this function's code?
body: <p>I am talking about the second &quot;return -1;&quot; on the 12th line of the code. This gets reached only if two sets of numbers are exactly the same, like when comparing '192.167.11' to '192.167.11'. I will also add that using range(0,2) would be a better option for this piece of code (range(0,3) produces errors if two elements happen to be the same; I did not change that as this is the original code example from PHP Array Exercise #21 from w3resource.com).</p>
  <pre><code>&lt;?php
  function sort_subnets($x, $y){
      $x_arr = explode('.', $x);
      $y_arr = explode('.', $y);
      foreach (range(0, 3) as $i) {
          if ($x_arr[$i] &lt; $y_arr[$i]) {
              return -1;
          } elseif ($x_arr[$i] &gt; $y_arr[$i]) {
              return 1;
          }
      }
      return -1;
  }
  
  $subnet_list =
      array('192.169.12',
          '192.167.11',
          '192.169.14',
          '192.168.13',
          '192.167.12',
          '122.169.15',
          '192.167.16'
      );
  usort($subnet_list, 'sort_subnets');
  print_r($subnet_list);
  ?&gt;
  </code></pre>
  <p>Returning &quot;-1&quot; would move the second element (the same as the first in the current $x and $y pair) towards the higher index of the array (down the array). Why not return &quot;0&quot; and keep everything as is if the two elements are exactly the same? Is there any reason for returning the &quot;-1&quot; maybe based on how the usort() works (or any other factor of this)?</p>
  <p>Thanks.</p>
  <h3>EDIT:</h3>
  <p>I think that this is Insertion Sort (array size 6-15 elements; normally it would be Quicksort).</p>