title: Multidimensional array to csv - how to create a second csv line for nested arrays
body: <p>I'm working with the following array.</p>
  
  <pre><code>Array
  (
  [0] =&gt; Array
      (
          [application_id] =&gt; 5234324
          [edition] =&gt; Enterprise
          [build_number] =&gt; 12.1.0.2.0
          [product] =&gt; Array
              (
                  [vendor] =&gt; Oracle
                  [name] =&gt; Oracle Database Server
              )
  
          [devices] =&gt; Array
              (
                  [0] =&gt; Array
                      (
                          [device_id] =&gt; 432432
                          [host_name] =&gt; node1
                          [serial_number] =&gt; hs3423523d
                          [manufacturer] =&gt; HP
                          [model] =&gt; ProLiant DL380 Gen9
                          [last_scan] =&gt; 2018-04-27 11:39:51
                      )
  
                  [1] =&gt; Array
                      (
                          [device_id] =&gt; 4ccf834b-43fa-4dd4-925a-9a3c96fadaf4
                          [host_name] =&gt; node2
                          [serial_number] =&gt; fdsgs35ed
                          [manufacturer] =&gt; HP
                          [model] =&gt; ProLiant DL380 Gen9
                          [last_scan] =&gt; 2018-04-27 08:24:08
                      )
  
              )
  
  
          [version] =&gt; 12c
  
      )
  
  )
  </code></pre>
  
  <p>Below is my code to create a cleaner array and then write the line to a single CSV file.</p>
  
  <pre><code>$array = json_decode($result, true);
  
  $applicationid = $data['application_id']?? '';
  $softwareedition = $data['edition']?? '';
  $buildnumber = $data['build_number']?? '';
  $hostname = $data['devices'][0]['host_name']?? '';
  $applicationversion = $data['version']?? '';
  
  $device_array = array($applicationid, $softwareedition, $buildnumber, 
  $hostname,$location, $location, $lastscan, $applicationversion);
  
  $fp = fopen('file.csv', 'a');
  
  fputcsv($fp, $device_array);
  
  fclose($fp);
  </code></pre>
  
  <p>This works great and the code writes the following line to the CSV file.</p>
  
  <p>5234324,Enterprise,12.1.0.2.0,node1,12c</p>
  
  <p>What I can't figure out is how to write a second CSV line as this particular array has two hostnames. So for such an array I would like to write two lines like this</p>
  
  <p>5234324,Enterprise,12.1.0.2.0,node1,12c</p>
  
  <p>5234324,Enterprise,12.1.0.2.0,node2,12c</p>
  
  <p>I found the array_key_exists function but it doesn't work with multidimensional arrays. Would some pseudo code work best here? Something like this inside an inner loop.</p>
  
  <p>GET HostnameCount
  i = 0
  WHILE i &lt; HostnameCount...</p>
  
  <p>Any help would be appreciated.</p>