Variable $total is an array().
print_r($total) gives:
Array (
[01] => Array ( [title] => text [date] => date )
[02] => Array ( [title] => text [date] => date )
[03] => Array ( [title] => text [date] => date )
)
How to write this array to file.txt?
And how to call created file later, so I can work with array inside it? Like:
$extracred_array = file.txt;
echo $extracred_array[1][title];
Thanks.
You need to serialize it with serialize function like this:
$serialize_array = serialize($array);
Now you can save the $serialize_array in your file. To read it back and convert to array again, use the unserialize function.
Update:
// write array data to file
file_put_contents('file.txt', serialize($your_array));
To read the file back:
// read array back from file
$contents = file_get_contents('file.txt');
// show the array
print_r(unserialize($contents));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With