Home php Rapid array in file

Rapid array in file

Author

Date

Category

So? I understood correctly?


1, Authority 100%


$ datalength = count ($ data);
For ($ i = 0; $ i & lt; $ DataLength; ++ $ i) {
   $ buff. = $ Data [$ i]. '';
}
// Cut the last space and add the transition to a new string
$ buff = substr ($ buff, 0, -1). "\ n"; // For Cyrilitsa
// If you work with UTF
MB_INTERNAL_ENCODING ('UTF-8');
$ buff = mb_substr ($ buff, 0, -1). "\ n";
// As an option you can avoid the need for substr completely
$ DataLength = Count ($ DATA);
For ($ i = 0; $ i & lt; $ DataLength; ++ $ i) {
   $ buff. = $ Data [$ i];
   if ($ i! = $ DataLength - 1) {
     $ buff. = '';
   }
}
$ buff. = "\ n";

// directly recording a string to a file
file_put_contents ($ File, $ buff, file_append);

PS: I have recently, such data is stored in JSON, it allows you to record the 1st line of the code to the file and in 1 line of the code to restore full-fledged arrays from the file. But this is a new-school 🙂

If the contents should be overwritten then simple to remove the File_APPend flag when calling file_put_contents


2, Authority 75%

The question is not quite clear. Need to record an array of $ DATA into an array of $ File or in a physical file?
If in a physical file, then you can do this:

& gt; $ Other_Mass = Serialize ($ DATA); // Generation of meanings
& gt;
& gt; $ F = Fopen ($ FileName, 'W'); // Open the file
& gt; FWRITE ($ F, $ Other_Mass); // write to it a generated value
& gt; FClose ($ F);

3

file_put_contents (__ dir__. 'log.php', Serialize ($ DATA));

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions