The problem is a bit around, dizzy people do not enter ^_^

Source: Internet
Author: User
Array (0 = = Array (' id ' = ' + ', ' title ' = ' A ', ' type ' = ' 1 ', ' bian ' = ' 1 '),
1 = = Array (' id ' = ' + ', ' title ' = ' A ', ' type ' = ' 1 ', ' Bian ' =>2),
2 = = Array (' id ' = ' = ', ' title ' = ' B ', ' type ' = ' 2 ', ' bian ' = ' 1 '),
3 = = Array (' id ' = ' = ', ' title ' = ' C ', ' type ' = ' 2 ', ' bian ' = ' 2 '),
)
When type=1 removes the same ID repetition and key becomes the ID, when type=2 the key becomes the Id_bian form, eventually turns into the following array
Array (0 = = Array (' + ' = ', ' 11_1 ' = ' = ', ' 11_2 ' = ') ')
Then merge with the following array
Array (0 + = array (' Ten ' = ' 1 ', ' 11_2 ' = ' 1 '),
1 = = Array (' Ten ' = ' 1 ', ' 11_2 ' = ' 1 '),
2 = = Array (' 11_1 ' = ' 1 ', ' 11_2 ' = ' 1 '),
3 = = Array (' Ten ' = ' 2 ', ' 11_2 ' = ' 1 '),
)
Eventually get
Array (0 + = array (' + ' = ' 1 ', ' 11_1 ' = ' = ', ' 11_2 ' = ' 1 '),
1 = = Array (' + ' = ' 1 ', ' 11_1 = ', ' 11_2 ' = ' 1 '),
2 = = Array (' ten ' = ' = ', ' 11_1 ' = ' 1 ', ' 11_2 ' = ' 1 '),
3 = = Array (' Ten ' + ' 2 ', ' 11_1 ' = ' = ', ' 11_2 ' = ' 1 '),
)


Reply to discussion (solution)

 $a = Array (0 = = Array (' id ' = ' + ', ' title ' = ' A ', ' type ' = ' 1 ', ' Bian ' =& gt; ' 1 '), 1 = = array (' id ' = ' + ', ' title ' = ' A ', ' type ' = ' 1 ', ' bian ' = ' 2 '), 2 = = Array (' id ' = ' 1 ') 1 ', ' title ' = ' B ', ' type ' = ' 2 ', ' bian ' = ' 1 '), 3 = = Array (' id ' = ' = ', ' title ' = ' C ', ' type ' = ' = ') 2 ', ' bian ' + ' 2 '), $b = Array (0 = = Array (' 1 ', ' 11_2 ' = ' 1 '), 1 = = Array (' + ' = ' 1 ', ' 11 _2 ' + ' 1 '), 2 = = Array (' 11_1 ' = ' 1 ', ' 11_2 ' = ' 1 '), 3 = = Array (' ' = ' 2 ', ' 11_2 ' = ' 1 '),); $  t = Array (), foreach ($a as $item) {if ($item [' type '] = = ' 1 ') {$t [$item [' id ']] = '; }else $t [$item [' id ']. ' _ '. $item [' bian ']] = ';}  $c = Array (); foreach ($b as $v) {$r = array ();  foreach ($t as $k = + $n) $r [$k] = @ $v [$k]; $c [] = $r;} Print_r ($c); 
Array (    [0] = = Array        (            [Ten] = 1            [11_1] =             [11_2] = 1        )    [1] = = Array        ( C8/>[10] = 1            [11_1] = [             11_2] = 1        )    [2] = = Array        (            [Ten] =             [11_1] =& Gt 1            [11_2] + 1        )    [3] = = Array        (            [ten] + 2            [11_1] =             [11_2] = 1        ) )

 $a = Array (0 = = Array (' id ' = ' + ', ' title ' = ' A ', ' type ' = ' 1 ', ' Bian ' =& gt; ' 1 '), 1 = = array (' id ' = ' + ', ' title ' = ' A ', ' type ' = ' 1 ', ' bian ' = ' 2 '), 2 = = Array (' id ' = ' 1 ') 1 ', ' title ' = ' B ', ' type ' = ' 2 ', ' bian ' = ' 1 '), 3 = = Array (' id ' = ' = ', ' title ' = ' C ', ' type ' = ' = ') 2 ', ' bian ' + ' 2 '), $b = Array (0 = = Array (' 1 ', ' 11_2 ' = ' 1 '), 1 = = Array (' + ' = ' 1 ', ' 11 _2 ' + ' 1 '), 2 = = Array (' 11_1 ' = ' 1 ', ' 11_2 ' = ' 1 '), 3 = = Array (' ' = ' 2 ', ' 11_2 ' = ' 1 '),); $  t = Array (), foreach ($a as $item) {if ($item [' type '] = = ' 1 ') {$t [$item [' id ']] = '; }else $t [$item [' id ']. ' _ '. $item [' bian ']] = ';}  $c = Array (); foreach ($b as $v) {$r = array ();  foreach ($t as $k = + $n) $r [$k] = @ $v [$k]; $c [] = $r;} Print_r ($c); 
Array (    [0] = = Array        (            [Ten] = 1            [11_1] =             [11_2] = 1        )    [1] = = Array        ( C8/>[10] = 1            [11_1] = [             11_2] = 1        )    [2] = = Array        (            [Ten] =             [11_1] =& Gt 1            [11_2] + 1        )    [3] = = Array        (            [ten] + 2            [11_1] =             [11_2] = 1        ) )


If you append $t as element in $c, do you want to re-traverse it?
Append Array (' ten ' = ', ' 11_1 ' + ', ' 11_2 ' = ' = ') as $c

I don't know what you mean.

I don't know what you mean.


$a = Array (0 = = Array (' id ' = ' + ', ' title ' = ' A ', ' type ' = ' 1 ', ' bian ' = ' 1 '), 1 = =  Array (' ID ' = ' + ', ' title ' = ' A ', ' type ' = ' 1 ', ' bian ' + ' 2 '),  2 = = Array (' id ' = ' = ', ' title ' = ' B ', ' Type ' = ' 2 ', ' bian ' = ' 1 '), 3 = = Array (' id ' = ' = ', ' title ' = ' C ', ' type ' = ' 2 ', ' bian ' = ' 2 '), 
  ); $b = Array (0 = = Array (' + ' = ' 1 ', ' 11_2 ' = ' 1 '),  1 = = Array (' + ' = ' 1 ', ' 11_2 ' = ' 1 '), 2 = = Array (' 11_1 ' = ' 1 ', ' 11_2 ' = ' 1 '), 3 = = Array (' + ' = ' 2 ', ' 11_2 ' = ' 1 '),  ); $t = array (); f Oreach ($a as $item) {  if ($item [' type '] = = ' 1 ') {    $t [$item [' id ']] = ';  } else $t [$item [' id ']. ' _ '. $item [' bian ']] = ';} $c = Array (); foreach ($b as $v) {  $r = array ();  foreach ($t as $k = + $n) $r [$k] = @ $v [$k];  $c [] = $r;} Print_r ($c);

Is that the result of the whole of array A is inserted into the $c, is it not certain to $c in the traversal?

Didn't traverse $c.

  • 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.