title: Convert multidimensional array keys to string
body: <p>I have a multidimensional array like this:</p>
  
  <pre><code>$array1['first']='myvalue1';
  $array1['second']=array();
  $array1['second']['first']='myvalue21';
  $array1['second']['second']='myvalue22';
  $array1['second']['third']=array();
  $array1['second']['third']['first']='myvalue231';
  $array1['second']['fourth']='myvalue24';
  $array1['third']='myvalue3';
  </code></pre>
  
  <p>And another array like:</p>
  
  <pre><code>$array2['second-first']='newvalue21';
  $array2['second-third-first']='newvalue231';
  </code></pre>
  
  <p>And I can't get the way to walk <code>$array1</code> recursively to check, in each iteration, if exist any element in <code>$array2</code> with a key equivalent to the current element key and their parents converted to string.</p>
  
  <p>To simplify the question, I will have enough with a function that prints something like:</p>
  
  <pre><code>// walking $array1:
  first
  second-first
  second-second
  second-third-first
  second-fourth
  third
  </code></pre>
  
  <p>Thank you.</p>
  
  <h2>Solution based on Clément Malet answer</h2>
  
  <pre><code>function print_array_reccur ($array1, $array2, $str = '') 
  {
      foreach ($array1 as $key =&gt; $val) {
          if (is_array($val)) {
              if ($str == '') {
                  print_array_reccur($val, $array2, $key);
              } else {
                  print_array_reccur($val, $array2, $str . '-' . $key);
              }
          } else {
              if ($str == '') {
                  $result = $key;
              } else {
                  $result = $str . '-' . $key;
              }
              if(isset($array2[$result]))
              {
                  echo 'Found $array2['.$result.'] = ' . $array2[$result] . "\n";
              }
          }
      }
  }
  
  print_array_reccur ($array1, $array2);
  
  /* OUTPUT:
  Found $array2[second-first] = newvalue21
  Found $array2[second-third-first] = newvalue231
  */
  </code></pre>