search

Home  >  Q&A  >  body text

How to solve the problem that the screen output is displayed as "ArrayArray" when writing a file?

<p>I have a method as follows. Simplify the code for clarity: </p> <pre class="brush:php;toolbar:false;">function somefunction($data){ $somestuff = createMyGeojson($data) write_aa_winter_sports_points_to_file($geojson); return $geojson; } function write_aa_winter_sports_points_to_file($content){ $file = "aa_winter_sports_points.geojson"; $dir = get_template_directory() .'/fs_data/aa_winter_sports_points/override_file_for_upload/'; file_put_contents($dir.$file, $content); }</pre> <p><code>return $geojson</code> displays the beautifully formatted json on the screen, but when I view my file all the corresponding data looks like <code>ArrayArray</ code>. I tried <code>print_r()</code> but it didn't help. How do I save the screen to a file using <code>file_put_contents()</code>? </p> <p>This is the current content of my file. </p> <p><code>FeatureCollectionaa_winter_sports_pointsArrayArray</code></p>
P粉757432491P粉757432491577 days ago594

reply all(1)I'll reply

  • P粉714780768

    P粉7147807682023-08-14 16:04:52

    If you want a string format similar to the output of print_r(), you can pass the second parameter true to the function.

    file_put_contents($dir.$file, print_r($content, true));

    reply
    0
  • Cancelreply