How to sort arrays in a random order in 1.2.3.4 text randomly select a row and combine it into a sentence, for example:
What are you doing? go for dinner. that's great.
Or
Great. I'm full. what do I do? I'm happy.
Reply to discussion (solution)
Using filenames=array('1.txt', '2.txt', '3.txt', '4.txt '); $ str = ''; foreach ($ filenames as $ k =>$ file) {$ tmp = file_get_contents ($ file ); $ data [$ k] = explode (PHP_EOL, $ tmp); $ str. = $ data [$ k] [array_rand ($ data [$ k])]. ',';} echo $ str; // Great. What are you doing after dinner? thank you,
Using filenames=array('1.txt', '2.txt', '3.txt', '4.txt '); $ str = ''; foreach ($ filenames as $ k =>$ file) {$ tmp = file_get_contents ($ file ); $ data [$ k] = explode (PHP_EOL, $ tmp); $ str. = $ data [$ k] [array_rand ($ data [$ k])]. ',';} echo $ str; // Great. What are you doing after dinner? thank you,
The iterator reads a sentence composed of a row.
The result I want is to randomly read a line from 1.2.3.4 to form a sentence.
Add the following sentence to your filenames=array('1.txt', '2.txt', '3.txt', '4.txt ');
Shuffle ($ filenames );
Add the following sentence to your filenames=array('1.txt', '2.txt', '3.txt', '4.txt ');
Shuffle ($ filenames );
Thank you very much. I am a beginner. I know a little bit about it, but I don't know the php writing method and sequence. I am very tired of it anyway.