php hierarchical array merge

Solutions on MaxInterview for php hierarchical array merge by the best coders in the world

showing results for - "php hierarchical array merge"
Nikki
02 Nov 2017
1
2<?php
3/* php hierarchical array merge */
4$temp = array();
5$temp[] = array(1,2,3);
6$temp[] = array(4,5,6);
7$temp[] = array(7,8,9);
8$demo = array();
9
10    $temp2 = array();
11    for($i=0;$i<count($temp);$i+=2)
12    {       
13        if(!isset($temp[$i+1]))
14        {
15            $temp[$i+1] = array();
16        }
17        $temp2 = array_merge($temp2,$temp[$i],$temp[$i+1]);
18    }
19
20    print_r($temp2);
21/*Array
22(
23    [0] => 1
24    [1] => 2
25    [2] => 3
26    [3] => 4
27    [4] => 5
28    [5] => 6
29    [6] => 7
30    [7] => 8
31    [8] => 9
32) */
33?>
34
35
similar questions
queries leading to this page
php hierarchical array merge