Answer the question
In order to leave comments, you need to log in
How to write php file with array?
I have a php file with the following content:
<?php
return [
'ID' => 'id',
'User ID' => 'user id',
'Total Price' => 'Total Price',
];
Answer the question
In order to leave comments, you need to log in
There is a built-in function var_export()
for this. To solve your problem, write something similar to this:
$filename = __DIR__.'/data.php'; // Путь куда записать содержимое файла
$string = "<?php\n return ".var_export($data, true).';';
file_put_contents($filename, $string);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question