title: Refactor function to search and replace values in multidimensional array
body: <p>I  have following multi dimensional array</p>
  
  <pre><code>$results = array(
      'name'     =&gt; 'signed_contract_message',
      'required' =&gt; ':min',
      'filters'  =&gt; array(
          array('name' =&gt; 'StripTags'),
          array('name' =&gt; 'StringTrim')
      ),
      'validators' =&gt; array(
          array('name' =&gt; ':max'),
          array(
              'name'    =&gt; 'StringLength',
              'options' =&gt; array(
                  'encoding' =&gt; 'UTF-8',
                  'min'      =&gt; ':min',
                  'max'      =&gt; ':max',
                  'values' =&gt; array(
                      'option_1' =&gt; ':min',
                      'option_2' =&gt; ':max'
                  )
              )
          )
      )
  );
  </code></pre>
  
  <p>I want to search and replace the occurrences of <code>:min</code> and <code>:max</code> which is stored in following array</p>
  
  <pre><code>$placeHolders = array(':min' =&gt; 2, ':max' =&gt; 100);
  </code></pre>
  
  <p>I created the following function to do the job</p>
  
  <pre><code>function searchAndReplacePlaceHolders($results, $placeHolders)
  {
      foreach ($results as $key =&gt; $result) {
          if (is_string($result) &amp;&amp; array_key_exists($result, $placeHolders)) {
              $results[$key] = $placeHolders[$result];
          }
          if (is_array($result)) {
              foreach ($result as $key1 =&gt; $result1) {
                  if (is_string($result1) &amp;&amp; array_key_exists($result1, $placeHolders)) {
                      $results[$key][$key1] = $placeHolders[$result];
                  }
                  if (is_array($result1)) {
                      foreach ($result1 as $key2 =&gt; $result2) {
                          if (is_string($result2) &amp;&amp; array_key_exists($result2, $placeHolders)) {
                              $results[$key][$key1][$key2] = $placeHolders[$result2];
                          }
                          if (is_array($result2)) {
                              foreach ($result2 as $key3 =&gt; $result3) {
                                  if (is_string($result3) &amp;&amp; array_key_exists($result3, $placeHolders)) {
                                      $results[$key][$key1][$key2][$key3] = $placeHolders[$result3];
                                  }
                              }
                              if (is_array($result3)) {
                                  foreach ($result3 as $key4 =&gt; $result4) {
                                      if (is_string($result4) &amp;&amp; array_key_exists($result4, $placeHolders)) {
                                          $results[$key][$key1][$key2][$key3][$key4] = $placeHolders[$result4];
                                      }
                                  }
                              }
                          }
                      }
                  }
              }
          }
      }
      return $results;
  }
  </code></pre>
  
  <p>This works, but what i wanted to know is if we can improve this function or perhaps do it in better way ?</p>
  
  <p>Thanks.</p>