How to sort arrays in random order

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.