Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the downgrade of multidimensional array by PHP

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report