title: How do I use a recursive array iterator to process a multidimensional array?
body: <p>I'm trying to get something like this working:</p>
  
  <pre><code>function posts_formatter (&amp;$posts){
      foreach ($posts as $k =&gt; $v){
  
          if (is_array($v)){
  
              posts_formatter($v);
  
          }else{
  
              switch (strtolower($k)){
  
                  # make email addresses lowercase
                  case (strpos($k, 'email') !== FALSE):
                      $posts[$k] = strtolower($v);
                      break;
  
                  # make postcodes uppercase
                  case (strpos($k, 'postcode') !== FALSE):
                      $posts[$k] = strtoupper($v);
                      break;
  
                  # capitalize certain things
                  case (strpos($k, 'line1') !== FALSE):
                  case (strpos($k, 'line2') !== FALSE):
                  case (strpos($k, 'line3') !== FALSE):
                  case (strpos($k, 'forename') !== FALSE):
                  case (strpos($k, 'surname') !== FALSE):
                      $posts[$k] = capitalize($v);
                      break;
              }
  
          }
      }
  }
  </code></pre>
  
  <p>It will correctly go through the array and format the values but I can't get it to return them. I've played around with removing the <code>&amp;</code> from the function declaration and adding a return at the end but it won't do anything.</p>
  
  <p>Additionally, I'm thinking perhaps using a <code>RecursiveArrayIterator</code> might be the way to go. However, despite the presence of a book right in front of me with a chapter on SPL Iterators its examples are useless towards being able to achieve what I'm trying to. How would I go about implementing one?</p>
  
  <p>Edit:</p>
  
  <pre><code>array (
    'user' =&gt; 
    array (
      'title' =&gt; 'Mr.',
      'forename' =&gt; 'lowercase',
      'surname' =&gt; 'name',
      'businessName' =&gt; 'some dude',
      'telephone' =&gt; '07545464646',
      'postcode' =&gt; 'wa1 6nj',
      'line1' =&gt; 'blergh road',
      'line2' =&gt; 'randomLY cApitaLIzed wOrds',
      'line3' =&gt; '',
    ),
    'email' =&gt; 'CAPITALIZED@BLERGH.com',
    'address' =&gt; 
    array (
      'postcode' =&gt; 'ab1 1ba',
      'line1' =&gt; 'test road',
      'line2' =&gt; 'testville',
      'line3' =&gt; 'testshire',
    ),
    'date' =&gt; '2010-09-30'
  )
  </code></pre>