PHP references in uasort function
<p>I have</p>

<pre><code>$products = array(
        "product1" =&gt; [
            "a" =&gt; ["total" =&gt; 1],
            "b" =&gt; ["total" =&gt; 3],
            "c" =&gt; ["total" =&gt; 2],
        ],
        "product2" =&gt; [
            "d" =&gt; ["total" =&gt; 3],
            "f" =&gt; ["total" =&gt; 2],
            "e" =&gt; ["total" =&gt; 1],
        ],
        "product3" =&gt; [
            "g" =&gt; ["total" =&gt; 3]
        ],
    );
</code></pre>

<p>theses are my products and my stocks for each warehouses (warehouse a has 1 item of product1...)</p>

<p>I want to sort each warehouse by stock for each products.
I've done that :</p>

<pre><code>foreach ($products as &amp;$stocks) {
        uasort($stocks, function($elmt1, $elmt2) {
            return $elmt2["total"] - $elmt1["total"];
        });
}
</code></pre>

<p>where I print my new array : </p>

<pre><code>array(3) {
  ["product1"]=&gt;
  array(3) {
    ["b"]=&gt;
    array(1) {
      ["total"]=&gt;
      int(3)
    }
    ["c"]=&gt;
    array(1) {
      ["total"]=&gt;
      int(2)
    }
    ["a"]=&gt;
    array(1) {
      ["total"]=&gt;
      int(1)
    }
  }
  ["product2"]=&gt;
  array(3) {
    ["d"]=&gt;
    array(1) {
      ["total"]=&gt;
      int(3)
    }
    ["f"]=&gt;
    array(1) {
      ["total"]=&gt;
      int(2)
    }
    ["e"]=&gt;
    array(1) {
      ["total"]=&gt;
      int(1)
    }
  }
  ["product3"]=&gt;
  &amp;array(1) {
    ["g"]=&gt;
    array(1) {
      ["total"]=&gt;
      int(3)
    }
  }
}
</code></pre>

<p>It did my job but when I get a closer look I can see the "&amp;" char in only one of the arrays.</p>

<p>Why ?</p>