Php breaks the simple example of an array two-dimensional array multi-dimensional array, and breaks the two-dimensional array _ PHP Tutorial

Source: Internet
Author: User
Php breaks the simple example of an array two-dimensional array multi-dimensional array and breaks down the two-dimensional array. Php breaks the simple example of a two-dimensional array multi-dimensional array, and the shuffle function in the two-dimensional array php can only disrupt the one-dimensional array. Is there any way to quickly and conveniently disrupt the multi-dimensional array? Manual php disrupt a simple example of an array two-dimensional array multi-dimensional array and disrupt a two-dimensional array

The shuffle function in php can only disrupt one-dimensional arrays. how can we quickly and conveniently disrupt multi-dimensional arrays? The manual provides

<?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 two-dimensional arrays!

What is the disordered method for multi-dimensional arrays below? As convenient and fast as possible:

<?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] = shuffle_assoc($list[$key]); return $random; } ?>

The following functions are also from the php Manual, which can disrupt multi-dimensional 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_values[$key] = rec_assoc_shuffle($ary_values[$key]);  }  $new[$value] = $ary_values[$key]; } return $new;}

The above is a simple example of a small series of php disrupting the array of two-dimensional arrays and multi-dimensional arrays. I hope you can provide more support ~

The shuffle function in sort php can only disrupt one-dimensional arrays. how can we quickly and conveniently disrupt multi-dimensional 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.