How to realize the downgrade of multidimensional array by PHP
This article will explain in detail how PHP can achieve multi-dimensional array degradation. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Multi-dimensional array degradation
Function array_flatten ($arr) {$result = []; array_walk_recursive ($arr, function ($value) use (& $result) {$result [] = $value;}); return $result;} print_r (array_flatten ([1, [2je 3], [4je 5]])) / / [1, [2jue 3], [4jre 5] = > [1pje 2je 3je 4je 5] / / var new_array = old_array.concat (value1 [, value2 [,... [, valueN]) var test = [1Jing 2jue 3, [4je 5rect 6], [7jue 8]; [] .concat.apply ([], test) For every value in the test array, concat it into the empty array [], and because concat is the prototype of Array, we use an empty array as the carrier var test1 = [1d2, [3, [4, [5]; function flatten (arr) {return arr.reduce (pre, cur) {if (Array.isArray (cur)) {return flatten (pre.concat (cur)) } return pre.concat (cur);}, []);} / / [1 result,JSON_UNESCAPED_UNICODE 2, 3 result,JSON_UNESCAPED_UNICODE 4 5] json_encode Chinese function json_encode_wrapper ($result) {if (defined ('JSON_UNESCAPED_UNICODE')) {return json_encode ($result,JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK) } else {return preg_replace (array ("#\\ u ([0-9a-f] [0-9a-f]) # ie", "/\" (\ d +)\ "/",), array ("iconv ('UCS-2',' UTF-8', pack ('H4','\ 1')", "\ 1"), json_encode ($result) }} this is the end of the article on "how to downgrade the multidimensional array in PHP". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.