Home > Backend Development > PHP Tutorial > How to merge subarrays of three-dimensional numbers

How to merge subarrays of three-dimensional numbers

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-09-21 14:13:13
Original
1112 people have browsed it

How to merge subarrays of three-dimensional numbers

Output the array in the above picture into the format below

How to merge subarrays of three-dimensional numbers

Thank you!!

Reply content:

How to merge subarrays of three-dimensional numbers

Output the array in the above picture into the format below

How to merge subarrays of three-dimensional numbers

Thank you!!

If it is determined that the third dimension has only one key-value pair, the third loop can be ignored

<code>$result_arr = array();
foreach($arr as $key => $data){
    foreach($data as $val) {
        $second_key = key($val);
        $result_arr[$key][$second_key] = $val[$second_key];
    }
}</code>
Copy after login

<code>$arr = array(
'初级' =>array(
    0=>array(
        2=>95,
        ),
    1=>array(
        3 => 423,
        )
    ),
'二级' => array(
    0=>array(
        4=>22,
        ),
    1=>array(
        5 => 43,
        )
    ),
);

foreach ($arr as $key => $value) {
    foreach ($value as $k => $v) {
        foreach ($v as $ks => $vs) {
            $arrs[$key][$ks] = $vs;
        }
        
    }
}
var_dump($arr);
var_dump($arrs);</code>
Copy after login

How to merge subarrays of three-dimensional numbers

Related labels:
php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template