PHP disrupts the shuffle_php tutorial by disrupting the use of shuffle functions and simple instances of the array

Source: Internet
Author: User
Tags shuffle shuffle shuffle

PHP disrupts the use of shuffle functions and simple instances of the array, disrupting shuffle


Shuffle ()

The PHP shuffle () function randomly arranges the order of the array cells (the array is scrambled). This function assigns the new key name to the cells in the array, which removes the existing key names and not just the reordering.

Grammar:

BOOL Shuffle (array &array)

Example 1:

<?php$arr = Range (1,8);p rint_r ($arr); Echo '
'; Shuffle ($arr);p rint_r ($arr); >

Run the example output:

It is necessary to note that each time the page is refreshed, the Print_r ($arr) results after shuffle ($arr) are different. Since PHP 4.2.0, it is no longer necessary to use Srand () and other functions to seed the random number generator and the system automatically completed.

Example 2, using associative arrays:

<?php$arr = Array ("A" =>1, "B" =>2, "C" =>3, "D" =>4, "E" =>5); Shuffle ($arr);p rint_r ($arr);? >

Run the example output:

Array ([0] = 5 [1] = 2 [2] = 1 [3] = 3 [4] = 4)

Of course, the results of each refresh of the page output are not the same.

The above is a small series for everyone to bring PHP to the array to disrupt the use of shuffle functions and simple examples of all the content, I hope that we support a lot of people to help the home ~

http://www.bkjia.com/PHPjc/1136628.html www.bkjia.com true http://www.bkjia.com/PHPjc/1136628.html techarticle PHP disrupts the use of shuffle functions and simple instances of the array, disrupting the shuffle Shuffle () PHP shuffle () function to randomly arrange the order of the array cells (the array is scrambled). This function is in the array ...

  • Related Article

    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.