title: Recursively update every element of multidimensional array
body: <p>I have a large multidimensional array like this:</p>
  
  <pre><code>$array = [
      'a' =&gt; 1,
      'b' =&gt; 5,
      'c' =&gt; [
          'c1' =&gt; 12,
          'c2' =&gt; [
              'd1' = 4,
              'd2' =&gt; 25
          ],
          'c3' =&gt; [/*...*/]
      ]
  ];
  </code></pre>
  
  <p>The array is of unknown size and dimension and I am trying to modify each element, for example to add 1 to every elements value.</p>
  
  <p>I've been googling around and found some recursive functions that visit each element and print its contents out, but nothing about modifying each element as you go.</p>
  
  <p>The following code (that I found online)</p>
  
  <pre><code>function x($a) {
      if (!is_array($a)) {
          echo ($a+1);
          return;
      }
  
      foreach($a as $v) {
          x($v);
      }
  }
  </code></pre>
  
  <p>allows me to print out the contents of the array, but how do you modify this to actually update the array elements with the calculation instead of echoing it out?</p>