PHP function shuffle () to achieve re-sorting _ PHP Tutorial

Source: Internet
Author: User
PHP function shuffle () to achieve re-sorting. In shuffle -- disrupt the array: the shuffle (arrayarray) PHP function shuffle () disconnects an array (the order of randomly arranged units. Note: The PHP function shuffle () is the unit in the array

Shuffle -- disrupt the array:
Bool shuffle (array & array)

The PHP function shuffle () is used to disrupt an array (the order of randomly arranged units.

Note: The PHP function shuffle () assigns a new key name to the cell in the array. This will delete the original key name, not just the reorder.

Example:

 
 
  1. <? Php
  2. $ A = array (
  3. '1' => 'Xiao ',
  4. '2' => 'da ',
  5. '3' => 'zuo ',
  6. '4' => 'you'
  7. );
  8. Echo "original array:". "<br/> ";
  9. Print_r ($ );
  10. Shuffle ($ );
  11. Echo "<br/>". "current array:". "<br/> ";
  12. Print_r ($ );
  13. ?>

Check the running result of the PHP function shuffle:

Original array:

Array ([1] => Xiao [2] => Da [3] => Zuo [4] => You)

Current array:

Array ([0] => Da [1] => Xiao [2] => You [3] => Zuo)

Of course, each time the page is refreshed, the order of elements in the "current array" changes once. Note that the key name of the array has changed.


Sort shuffle -- disrupt the array: the shuffle (array) PHP function shuffle () disrupts an array (the order of randomly arranged units. Note: PHP function shuffle () is the unit in array...

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.