How to solve the problem that the screen output is displayed as "ArrayArray" when writing a file?
P粉757432491
2023-08-13 20:03:27
<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>
If you want a string format similar to the output of
print_r()
, you can pass the second parametertrue
to the function.