uasort change array order before doing any 'user-defined' function
<p>To start with, sorry if the title is not really clear.</p>

<p>Basically, I have an array containing 2 arrays that goes through a script that uses uasort.
Because for this specific array I didn't have the wanted behavior, I tried using a code as simple as possible that would reproduce my "bug":</p>

<pre><code>&lt;?php 
$myArray = array(
                 0 =&gt; array(
                      0 =&gt;  array(  'field1' =&gt; "2.1",
                                    'filed2' =&gt; 1815199),
                      1 =&gt;  "database.table",
                      2 =&gt;  array(),
                      3 =&gt;  NULL
                ),
                1 =&gt; array(
                      0 =&gt;  array(  'field1' =&gt; "3.7",
                                    'filed2' =&gt; 1815199),
                      1 =&gt;  "database.table",
                      2 =&gt;  array(),
                      3 =&gt;  NULL
                )
);

echo '@@~~}}~~@@  ';
var_dump( $myArray);

uasort( $myArray, "order_del_upd_ins" );

echo '@@~~{{~~@@  ';
var_dump( $myArray);

function order_del_upd_ins( $a, $b )
{
    echo '~~@@~~@@##@@~~@@~~ ';
    var_dump( $a);
    var_dump( $b);


   return 0;
}?&gt;
</code></pre>

<p>So basically my first array contains the value 2.1, and the second array 3.7.</p>

<p>But when I print them, after going through the uasort (where I don't do anything), my second array gets first, and the first second:</p>

<pre><code>@@~~}}~~@@  
array(2) {
[0] =&gt; array(4) {
      [0] =&gt;
         array(2) {
           'field1' =&gt; string(3) "2.1"
           'filed2' =&gt; int(1815199)
        }
      [1] =&gt; string(14) "database.table"
      [2] =&gt; array(0) {}
      [3] =&gt; NULL
    }
[1] =&gt; array(4) {
     [0] =&gt; array(2) {
              'field1' =&gt; string(3) "3.7"
              'filed2' =&gt; int(1815199)
            }
     [1] =&gt; string(14) "database.table"
     [2] =&gt; array(0) {}
     [3] =&gt; NULL
    }
}

~~@@~~@@##@@~~@@~~ 
array(4) {
[0] =&gt;
    array(2) {
       'field1' =&gt; string(3) "3.7"
       'filed2' =&gt; int(1815199)
    }
[1] =&gt; string(14) "database.table"
[2] =&gt; array(0) {}
[3] =&gt; NULL
}

array(4) {
[0] =&gt; array(2) {
    'field1' =&gt; string(3) "2.1"
    'filed2' =&gt; int(1815199)
    }
[1] =&gt; string(14) "database.table"
[2] =&gt; array(0) {}
[3] =&gt; NULL
}

@@~~{{~~@@  
array(2) {
[1] =&gt; array(4) {
       [0] =&gt;
          array(2) {
            'field1' =&gt; string(3) "3.7"
            'filed2' =&gt; int(1815199)
         }
       [1] =&gt; string(14) "database.table"
       [2] =&gt; array(0) {}
       [3] =&gt; NULL
   }
[0] =&gt; array(4) {
       [0] =&gt;
          array(2) {
            'field1' =&gt; string(3) "2.1"
            'filed2' =&gt; int(1815199)
          }
       [1] =&gt; string(14) "database.table"
       [2] =&gt; array(0) {}
       [3] =&gt; NULL
   }
}
</code></pre>

<p>So basiccaly, I have an array of 2 elements, going to a function uasort that doesnt do anything, but as soon as it goes in, the elements are not ordered properly anymore.</p>

<p>According to php manual:</p>

<blockquote>
  <p>uasort — Sort an array with a user-defined comparison function and
  maintain index association</p>
</blockquote>

<p>So from what I understand, if I don't specify anything in my 'user-defined' function, nothing should change in my array right ??</p>

<p>Does anyone have an idea of what is going on ?</p>

<p>Thanks a lot</p>
