title: str_replace and ucwords for multidimensional array
body: <p>I am struggling to get <code>$_POST</code> values capitalize and removing underscore if it is not the <code>mailaddress</code> field. I am almost there but not able to remove the underscore from checkbox group array. Also, I believe, there must be some better way to optimize this code.</p>
  
  <pre><code>$_POST = str_replace( '_', ' ', $_POST );
  
  foreach ( $_POST as $k =&gt; $v ) {
      if ( ! is_array( $v ) &amp;&amp; $k != 'mailaddress' ) {
          $_POST[ $k ] = ucwords( $v );
      } else if ( is_array( $v ) ) {
          $_POST[ $k ] = array_map( 'ucwords', $v );
      }
  }
  </code></pre>
  
  <h1>Input</h1>
  
  <pre><code>Array
  (
      [Q1] =&gt; Array
          (
              [0] =&gt; tag
              [1] =&gt; bil_mc
              [2] =&gt; cykel_gang
          )
  
      [Q2] =&gt; 1 3 ganger per manad
      [Q3] =&gt; pa fritiden
      [Q4] =&gt; Array
          (
              [0] =&gt; koper_biljett_i_appen
              [1] =&gt; jojo_reskassa
              [2] =&gt; jojo_period
              [3] =&gt; reser_aldrig_kollektivt
          )
  
      [mailaddress] =&gt; 'me@email.com'
  
      ...
  
  );
  </code></pre>
  
  <h1>Looking for end result</h1>
  
  <pre><code>Array
  (
      [Q1] =&gt; Array
          (
              [0] =&gt; Tag
              [1] =&gt; Bil Mc
              [2] =&gt; Cykel Gang
          )
  
      [Q2] =&gt; 1 3 Ganger Per Manad
      [Q3] =&gt; Pa Fritiden
      [Q4] =&gt; Array
          (
              [0] =&gt; Koper Biljett I Appen
              [1] =&gt; Jojo Reskassa
              [2] =&gt; Jojo Period
              [3] =&gt; Reser Aldrig Kollektivt
          )
  
      [mailaddress] =&gt; 'me@email.com'
  
      ...
  
  );
  </code></pre>
  
  <p>Any help or sugession please???</p>