The first time in the StackOverflow asked, bright blind.

Source: Internet
Author: User

See the OC code in the afternoon, see such a sentence


Array_multisort ($sort _order, SORT_ASC, $method _data);

This is the sort of multiple arrays, but there is nothing to say. Then I gave myself a question, and that's it.


Requires that the lowercase of this array be all capitalized abcdefgh, to be honest, tangled for 2 hours.

Want to recursive, want to judge the depth of the array.

Then the semi-finished product is this result:

function Array_depth ($array) {        $max _depth = 1;        foreach ($array as $value) {            if (Is_array ($value)) {                $depth = array_depth ($value) + 1;                if ($depth > $max _depth) {                    $max _depth = $depth;}}        }                return $max _depth; }array_depth ($ar); function Toto ($arr, $depth = ' 1 ') {$tem =array (); foreach ($arr as $key + = $value) {if (Is_string ($ Value) {$tem []=strtoupper ($value);} ElseIf (Is_array ($value) &&array_depth ($value) >1) {//$J =str_repeat (' [] ', (array_depth ($value)));   $tem []=array_map (' Strtoupper ', $value);} else{$tem []= $value;}} return $tem;}

The first one is to judge the depth of the array, I think the depth and then use $arr[][][] such a way to fill, two-dimensional array can be solved, but three-dimensional, four-dimension it. And the problem comes,

$arr 1[][][]=5; $j =str_repeat (' [] ', 3);

It is not feasible to use $ARR1. $j.


What to do, go to the legendary StackOverflow, I also overflow a bit.

Foreigners are really good, I wrote a question for 3 minutes, waiting for someone to answer for 10 seconds.

The first friend said to use a function on the line, do not need to know what the array depth. So the function is array_walk_recursive, previously just simple used array_map,array_map can not recursion, so he recommended this.

I tried it, still can achieve part of the effect, enough, the code is as follows

$arr = Array (ten, 102, 199, "a" =>array (' B ', ' C ', ' d ' =>array (' e ', ' f ')), ' G ', ' h '); Array_walk_recursive ($arr, function (& $value, $key) {$value = Strtoupper ($value);}); Var_dump ($arr);

But interesting to come, because I said to become abcdef, and then have to answer the person will not be happy, said Op said D also changed, op i Baidu, may be the landlord, editor's meaning.

Then the first person who answered my question said that the value of the key could not be changed.

Then the second person clicks, show he the code

Then there is the following brilliant answer, bright blind.

$arr = Array (ten, 102, 199, "a" =>array (' B ', ' C ', ' d ' =>array (' e ', ' f ')), ' G ', ' h '); $arr = Json_decode (Strtoupper (Json_encode ($arr)), true) Var_dump ($arr);d ie;

The result is really abcdef, I don't know why.

Still need to get the PHP array function thoroughly.

Also attached address, to turn over the wall: http://stackoverflow.com/questions/31114927/ How-do-i-change-the-unknown-array-depth-and-change-all-of-the-letters-from-lower

PS: Do not worry about your English low, someone will be corrected. Oh, great God.





Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The first time in the StackOverflow asked, bright blind.

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.