title: Update a multidimensional array
body: <p>I'm trying to update my array but it doesn't work as expected!</p>
  
  <p>I got this array:</p>
  
  <pre><code>Array
  (
  [0] =&gt; Array
      (
          [0] =&gt; property_unit Object
              (
                  [unit] =&gt; one bedroom
                  [details] =&gt; Array
                      (
                          [0] =&gt; propertydetails Object
                              (
                                  [priority] =&gt; 3
                                  [size] =&gt; 54
                                  [percentage] =&gt; 0
                                  [search] =&gt; 1
                              )
  
                      )
  
              )
  
          [1] =&gt; property_unit Object
              (
                  [unit] =&gt; two bedroom
                  [details] =&gt; Array
                      (
                          [0] =&gt; propertydetails Object
                              (
                                  [priority] =&gt; 1
                                  [size] =&gt; 74
                                  [percentage] =&gt; 0
                                  [search] =&gt; 1
                              )
  
                      )
  
              )
  
          [2] =&gt; property_unit Object
              (
                  [unit] =&gt; three bedroom
                  [details] =&gt; Array
                      (
                          [0] =&gt; propertydetails Object
                              (
                                  [priority] =&gt; 1
                                  [size] =&gt; 90
                                  [percentage] =&gt; 0
                                  [search] =&gt; 1
                              )
  
                      )
  
              )
  
          [3] =&gt; property_unit Object
              (
                  [unit] =&gt; studio
                  [details] =&gt; Array
                      (
                          [0] =&gt; propertydetails Object
                              (
                                  [priority] =&gt; 2
                                  [size] =&gt; 22.35
                                  [percentage] =&gt; 0
                                  [search] =&gt; 1
                              )
  
                      )
  
              )
  
      )
  
  [1] =&gt; Array
      (
          [0] =&gt; property_unit Object
              (
                  [unit] =&gt; one bedroom
                  [details] =&gt; Array
                      (
                          [0] =&gt; propertydetails Object
                              (
                                  [priority] =&gt; 3
                                  [size] =&gt; 54
                                  [percentage] =&gt; 0
                                  [search] =&gt; 1
                              )
  
                      )
  
              )
  
          [1] =&gt; property_unit Object
              (
                  [unit] =&gt; two bedroom
                  [details] =&gt; Array
                      (
                          [0] =&gt; propertydetails Object
                              (
                                  [priority] =&gt; 1
                                  [size] =&gt; 74
                                  [percentage] =&gt; 0
                                  [search] =&gt; 1
                              )
  
                      )
  
              )
  
          [2] =&gt; property_unit Object
              (
                  [unit] =&gt; studio
                  [details] =&gt; Array
                      (
                          [0] =&gt; propertydetails Object
                              (
                                  [priority] =&gt; 2
                                  [size] =&gt; 22.35
                                  [percentage] =&gt; 0
                                  [search] =&gt; 1
                              )
  
                      )
  
              )
  
          [3] =&gt; property_unit Object
              (
                  [unit] =&gt; three bedroom
                  [details] =&gt; Array
                      (
                          [0] =&gt; propertydetails Object
                              (
                                  [priority] =&gt; 1
                                  [size] =&gt; 90
                                  [percentage] =&gt; 0
                                  [search] =&gt; 1
                              )
  
                      )
  
              )
  
      )
  
  [2] =&gt; Array
      (
          [0] =&gt; property_unit Object
              (
                  [unit] =&gt; one bedroom
                  [details] =&gt; Array
                      (
                          [0] =&gt; propertydetails Object
                              (
                                  [priority] =&gt; 3
                                  [size] =&gt; 54
                                  [percentage] =&gt; 0
                                  [search] =&gt; 1
                              )
  
                      )
  
              )
  
          [1] =&gt; property_unit Object
              (
                  [unit] =&gt; three bedroom
                  [details] =&gt; Array
                      (
                          [0] =&gt; propertydetails Object
                              (
                                  [priority] =&gt; 1
                                  [size] =&gt; 90
                                  [percentage] =&gt; 0
                                  [search] =&gt; 1
                              )
  
                      )
  
              )
  
          [2] =&gt; property_unit Object
              (
                  [unit] =&gt; two bedroom
                  [details] =&gt; Array
                      (
                          [0] =&gt; propertydetails Object
                              (
                                  [priority] =&gt; 1
                                  [size] =&gt; 74
                                  [percentage] =&gt; 0
                                  [search] =&gt; 1
                              )
  
                      )
  
              )
  
          [3] =&gt; property_unit Object
              (
                  [unit] =&gt; studio
                  [details] =&gt; Array
                      (
                          [0] =&gt; propertydetails Object
                              (
                                  [priority] =&gt; 2
                                  [size] =&gt; 22.35
                                  [percentage] =&gt; 0
                                  [search] =&gt; 1
                              )
  
                      )
  
              )
  
      )
  )
  </code></pre>
  
  <p>and using var_dump()</p>
  
  <pre><code>array (size=24)
    0 =&gt; 
      array (size=4)
        0 =&gt; 
          object(property_unit)[1]
            public 'unit' =&gt; string 'one bedroom' (length=11)
            public 'details' =&gt; 
              array (size=1)
                ...
        1 =&gt; 
          object(property_unit)[3]
            public 'unit' =&gt; string 'two bedroom' (length=11)
            public 'details' =&gt; 
              array (size=1)
                ...
        2 =&gt; 
          object(property_unit)[5]
            public 'unit' =&gt; string 'three bedroom' (length=13)
            public 'details' =&gt; 
              array (size=1)
                ...
        3 =&gt; 
          object(property_unit)[7]
            public 'unit' =&gt; string 'studio' (length=6)
            public 'details' =&gt; 
              array (size=1)
                ...
    1 =&gt; 
      array (size=4)
        0 =&gt; 
          object(property_unit)[1]
            public 'unit' =&gt; string 'one bedroom' (length=11)
            public 'details' =&gt; 
              array (size=1)
                ...
        1 =&gt; 
          object(property_unit)[3]
            public 'unit' =&gt; string 'two bedroom' (length=11)
            public 'details' =&gt; 
              array (size=1)
                ...
        2 =&gt; 
          object(property_unit)[7]
            public 'unit' =&gt; string 'studio' (length=6)
            public 'details' =&gt; 
              array (size=1)
                ...
        3 =&gt; 
          object(property_unit)[5]
            public 'unit' =&gt; string 'three bedroom' (length=13)
            public 'details' =&gt; 
              array (size=1)
                ...
    2 =&gt; 
      array (size=4)
        0 =&gt; 
          object(property_unit)[1]
            public 'unit' =&gt; string 'one bedroom' (length=11)
            public 'details' =&gt; 
              array (size=1)
                ...
        1 =&gt; 
          object(property_unit)[5]
            public 'unit' =&gt; string 'three bedroom' (length=13)
            public 'details' =&gt; 
              array (size=1)
                ...
        2 =&gt; 
          object(property_unit)[3]
            public 'unit' =&gt; string 'two bedroom' (length=11)
            public 'details' =&gt; 
              array (size=1)
                ...
        3 =&gt; 
          object(property_unit)[7]
            public 'unit' =&gt; string 'studio' (length=6)
            public 'details' =&gt; 
              array (size=1)
                ...
    3 =&gt; 
  </code></pre>
  
  <p>I got this array with this:</p>
  
  <pre><code>$array = [new property_unit('one bedroom', [new propertydetails(1, 54, 0, 1)]),
      new property_unit('two bedroom', [new propertydetails(1, 74, 0, 1)]),
          new property_unit('three bedroom', [new propertydetails(1, 90, 0, 1)]),
              new property_unit('studio', [new propertydetails(2, 22.35, 0, 1)])];
  </code></pre>
  
  <p>Then I perform a computation on it to get all the possible array.</p>
  
  <pre><code>function computePermutations($array) {
      $result = [];
  
      $recurse = function($array, $start_i = 0) use (&amp;$result, &amp;$recurse) {
          if ($start_i === count($array)-1) {
              array_push($result, $array);
          }
  
          for ($i = $start_i; $i &lt; count($array); $i++) {
              //Swap array value at $i and $start_i
              $t = $array[$i]; 
              $array[$i] = $array[$start_i]; 
              $array[$start_i] = $t;
  
              //Recurse
              $recurse($array, $start_i + 1);
  
              //Restore old order
              $t = $array[$i]; 
              $array[$i] = $array[$start_i]; 
              $array[$start_i] = $t;
          }
      };
  
      $recurse($array);
  
      return $result;
  }
  //I assign to my array
  $array = computePermutations($array);
  </code></pre>
  
  <p><em>I thing something maybe goes wrong here ?</em></p>
  
  <p>but when I'm trying to update my array like :</p>
  
  <pre><code>$array[0][0]-&gt;details[0]-&gt;priority = 3;
  </code></pre>
  
  <p>It update all the first priority field, (see the array before) this is after the update.</p>
  
  <p>Meaning:</p>
  
  <pre><code>$array[0][0]-&gt;details[0]-&gt;priority
  $array[1][0]-&gt;details[0]-&gt;priority
  $array[2][0]-&gt;details[0]-&gt;priority
  </code></pre>
  
  <p>etc... becomes 3</p>
  
  <p>Any idea where this can come from, is there any other way to update a multidimensional array? Am I doing something wrong here?</p>