title: Export multidimensional array of objects as CSV
body: <p>I have an array <code>$csvRows</code> like the following. I want to export that array as CSV.</p>
  
  <pre><code>Array
  (
      [0] =&gt; SingleModule Object
          (
              [module:SingleModule:private] =&gt; Module Object
                  (
                      [name:Module:private] =&gt; SimpleXMLElement Object
                          (
                              [0] =&gt; some string
                          )
  
                      [position:Module:private] =&gt; SimpleXMLElement Object
                          (
                              [0] =&gt; 1000
                          )
  
                      [config:Module:private] =&gt; SimpleXMLElement Object
                          (
                          )
  
                  )
  
              [moduleMeta:SingleModule:private] =&gt; ModuleMeta Object
                  (
                      [description:ModuleMeta:private] =&gt; description text
                      [featureOrUseCase:ModuleMeta:private] =&gt; feature or usecase text
                      [inputParam:ModuleMeta:private] =&gt; input Parameter text
                      [changedParam:ModuleMeta:private] =&gt; changed Parameter text
                      [newOutputParam:ModuleMeta:private] =&gt; new Output Param text
                      [commentOrNote:ModuleMeta:private] =&gt; comments Or Note text
                  )
  
          )
  
      [1] =&gt; SingleModule Object
           (etc...)
  </code></pre>
  
  <p>I have already tried the solution, which I found in <a href="https://stackoverflow.com/questions/28322751/create-csv-from-multidimensional-array-with-fputcsv">this link</a>. Here is my code sample:</p>
  
  <pre><code>$fileName = "../../data/modules.csv";
  $output = fopen($fileName, 'w+');
  foreach ( $csvRows as $file ) {
      $result = [ ];
      array_walk_recursive($file, function ($item) use (&amp;$result) {
          $result [] = $item;
      });
      fputcsv($output, $result);
  }
  fclose($output);
  </code></pre>
  
  <p>Then I get the following error:</p>
  
  <pre><code>PHP Recoverable fatal error:  Object of class Module could not be converted to string ...in line where fputcsv is.
  </code></pre>
  
  <p>I have temporarily solved the problem by manually creating a straightforward array like the following, which I found in <a href="https://stackoverflow.com/questions/3933668/convert-array-into-csv">this link</a>:</p>
  
  <pre><code> $csvRows = array(
          array( 'row_1_col_1', 'row_1_col_2', 'row_1_col_3' ),
          array( 'row_2_col_1', 'row_2_col_2', 'row_2_col_3' ),
          array( 'row_3_col_1', 'row_3_col_2', 'row_3_col_3' ),
      );
  </code></pre>
  
  <p>But I want to export my actual <code>$csvRows</code> array of objects as CSV. I am a newbie programmer, so any suggestion and help would highly appreciated.</p>