PHP disrupts two-dimensional array of arrays in a simple instance of the array, disrupting the second-dimensional array _php tutorial

Source: Internet
Author: User
Tags shuffle

PHP scrambles a simple instance of an array of two-dimensional arrays, disrupting a two-dimensional array


The shuffle function in PHP can only disrupt one-dimensional arrays, what are the ways to quickly and easily disrupt multidimensional arrays? The manual provides a

<?php function Shuffle_assoc ($list) {  if (!is_array ($list)) return $list;  $keys = Array_keys ($list);  Shuffle ($keys);  $random = Array ();  foreach ($keys as $key)   $random [$key] = $list [$key];  return $random; }?>

The above is for a two-dimensional array!

The following method for the chaos of multidimensional arrays? As convenient and quick as possible :

<?php function Shuffle_assoc ($list) {if (!is_array ($list)) return $list; $keys = Array_keys ($list); shuffle ($keys); $r Andom = Array (); foreach ($keys as $key) $random [$key] = Shuffle_assoc ($list [$key]); return $random; }?>

The following functions are also derived from the PHP manual, which can disrupt multidimensional arrays:

/*** shuffles an associative array recursive* * @param array $array * @return array**/function rec_assoc_shuffle ($array) {$ Ary_keys = Array_keys ($array); $ary _values = array_values ($array); Shuffle ($ary _values); foreach ($ary _keys as $key = + $value) {  if (Is_array ($ary _values[$key]) and $ary _values[$key]! = NULL) {   $ary _v alues[$key] = rec_assoc_shuffle ($ary _values[$key]);  }  $new [$value] = $ary _values[$key]; } return $new;}

The above is a small series of PHP for everyone to disrupt the array of arrays of two-dimensional array of a simple example of all the content, I hope you have a lot of support to help the home ~

http://www.bkjia.com/PHPjc/1136627.html www.bkjia.com true http://www.bkjia.com/PHPjc/1136627.html techarticle PHP scrambled array of two-dimensional array of a simple example of a multidimensional array, disrupting the two-dimensional array php shuffle function can only disrupt one-dimensional array, there is no way to quickly and easily scrambled multidimensional arrays? Manual ...

  • 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.