Array conversion Merge

Source: Internet
Author: User
Array ([0] = = Array ([id] = 9 [Ti] = Me) [1] = = Array ([id] = [ti] + =) [2] = = Array ([ID] = = [Ti] = in) [3] = = Array ([id] = [ti] = country))
This translates into a one-dimensional array id as key, the conversion I would, but encountered the same on the merge how to do?
If you get a one-dimensional array, combine the resulting one-dimensional array with the following, and replace the value if key is equal;
Array ([7] = love [8] = = I [9] = = [Ten]--33333 [one] = [[ALL] = China]

There are two problems encountered in the current practice array, please master guidance. After a quick day, or failed ... -_-


Reply to discussion (solution)

$a = Array (  ' id ' = = 9,  ' ti ' = ' i '), array (' id ' = ' = ',  ' ti ' = ') ',  array (' ID ' =& Gt One, ' ti ' = ' in '),  Array (' id ' = = ', ' ti ' = ') '), $res = Array (), foreach ($a as $r) {  if (isset ($res [$r [ ' ID '])) $res [$r [' ID ']]. = $r [' ti '];  else $res [$r [' id ']] = $r [' Ti '];} Print_r ($res);
Array (    [9] = = i    [ten] [all]    [one] = China)

$a = Array (  ' id ' = = 9,  ' ti ' = ' i '), array (' id ' = ' = ',  ' ti ' = ') ',  array (' ID ' = = ', ' ti ' = ' in '),  Array (' id ' = = ', ' ti ' + ') '), $res = Array (); foreach ($a as $r) {  if (Isse T ($res [$R [' ID ']]) $res [$r [' ID ']]. = $r [' ti '];  else $res [$r [' id ']] = $r [' Ti '];} Print_r ($res);
Array (    [9] = = i    [ten] [all]    [one] = China)


Moderator sorry I also want to ask $res[$r [' id ']. = $r [' ti ']; what is the symbol used for? If you merge $res with the following array, the same key is encountered to replace his value. Can you do that?
Array ([7] = love [8] = = I [9] = = [Ten]--33333 [one] = [[ALL] = China]

Haha, has been using Array_merge () merged, the original directly with the + number on the line ....

  • Related Article

    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.