Would you like to ask the PHP two-dimensional array to find the same value for the merge?

Source: Internet
Author: User
This is an array.
The main function is the result of the query in the thinkphp view model I think

Querying the same header values in each array and then merging the merged arrays seems to be using Array_merge ()
How do I find the same title? The foreach Traversal returns the index value in the array. It looks like the key () function has this function to ask the kindly person to write a specific

The position of the same header array element so that when you return to the merge, you can use this form directly.
Array_merge (Array[0],array[1])

The same title then merges the connection fields of the picture so Pictureurl is not the same.
Simple to say is more than the picture upload article such articles look for if there are thousands of of the array is several times the amount of efficient calculation can be used for the big God pointing ah ~
Such
Array (2) {  [0] = = Array (5) {    ["pictitle"] = + string (33) "Title 1"    ["Piccategroy"] + string (6) "category"    ["picauthor"] = + string (12) "Author"    ["Picposttime"] + string (+) "2014-11-20 16:05:16"    ["Pictureurl"] and "= string" attachment/picture/ Uploadify/20141120/546da0784831c.png "  }  [1] = = Array (5) {    [" pictitle "] + = string (33)" Heading 1 "    [" Piccategroy "] + string (6)" Classification "    [" picauthor "] + + string (12)" Author "    [" picposttime "] = + string (19)" 2014-11-20 16:05:16 "    [" Pictureurl "] and string" Attachment/picture/uploadify/20141120/546da0746edb8.png "  }}


Reply to discussion (solution)

So what are your final results?
Different purposes, the algorithm is different

So what are your final results?
Different purposes, the algorithm is different


Array (2) {  [0] = = Array (5) {    ["pictitle"] = + string (33) "Title 1"    ["Piccategroy"] + string (6) "category"    ["picauthor"] = + string (12) "Author"    ["Picposttime"] + string (+) "2014-11-20 16:05:16"    ["Pictureurl"] and "= string" attachment/picture/ Uploadify/20141120/546da0784831c.png,attachment/picture/uploadify/20141120/546da0746edb8.png "  }}

That's the same title. The difference is pictureurl.
Merge on the line to ask the moderator guidance ~

$ar = Array (    "Pictitle" and "Title 1",    "Piccategroy" and "category",    "picauthor" = "Author",    " Picposttime "=" 2014-11-20 16:05:16 ",    " pictureurl "=" attachment/picture/uploadify/20141120/" 546da0784831c.png ","  ),  Array (    "Pictitle" and "Title 1",    "Piccategroy" and "category",    "picauthor" = > "Author",    "picposttime" = "2014-11-20 16:05:16",    "Pictureurl" and "attachment/picture/uploadify/" 20141120/546da0746edb8.png ",  ),); foreach (Call_user_func_array (' array_merge_recursive ', $ar) as $key =>$ Item) {  $res [$key] = join (', ', Array_unique ($item));} Var_export ($res);
Array (' pictitle ' = ' + '  Title 1 ',  ' piccategroy ' = ' category ', ' picauthor ' = '  author ',  ' picposttime ' = > ' 2014-11-20 16:05:16 ',  ' pictureurl ' = ' attachment/picture/uploadify/20141120/546da0784831c.png, Attachment/picture/uploadify/20141120/546da0746edb8.png ',)

$ar = Array (    "Pictitle" and "Title 1",    "Piccategroy" and "category",    "picauthor" = "Author",    " Picposttime "=" 2014-11-20 16:05:16 ",    " pictureurl "=" attachment/picture/uploadify/20141120/" 546da0784831c.png ","  ),  Array (    "Pictitle" and "Title 1",    "Piccategroy" and "category",    "picauthor" = > "Author",    "picposttime" = "2014-11-20 16:05:16",    "Pictureurl" and "attachment/picture/uploadify/" 20141120/546da0746edb8.png ",  ),); foreach (Call_user_func_array (' array_merge_recursive ', $ar) as $key =>$ Item) {  $res [$key] = join (', ', Array_unique ($item));} Var_export ($res);
Array (  ' pictitle ' = ' + ' Title 1 ',  ' piccategroy ' = ' ' category ',  ' picauthor ' = ' author ', '  picposttime ' = ' 2014-11-20 16:05:16 ',  ' pictureurl ' = ' attachment/picture/uploadify/20141120/546da0784831c.png,attachment/ Picture/uploadify/20141120/546da0746edb8.png ',)


Moderator adults also have to trouble you look at this is the same title under the merger seems a little complicated
Array (6) {[0] = = Array (5) {["pictitle"] + = string (7) "Title 2" ["Piccategroy"] + string (6) "poster" ["Picaut  Hor "] + string (12)" Star Yao Gakuen "[" Picposttime "] + string (+)" 2014-11-26 11:59:50 "[" Pictureurl "] + string (55)    "Attachment/picture/uploadify/20141126/547550278b7db.jpg"} [1] = = Array (5) {["pictitle"] = + string (7) "Heading 2" ["Piccategroy"] + + string (6) "poster" ["Picauthor"] + + string (12) "Star Yao Gakuen" ["Picposttime"] + string (19) "2014 -11-26 11:59:50 "[" Pictureurl "] + string (in)" Attachment/picture/uploadify/20141126/54755027ab89b.jpg "} [2] =&gt ;  Array (5) {["pictitle"] + = string (7) "Title 2" ["Piccategroy"] + string (6) "poster" ["Picauthor"] + string (12) "Star Yao Gakuen" ["Picposttime"] + string (+) "2014-11-26 11:59:50" ["pictureurl"] = = string "attachment/picture/u Ploadify/20141126/547550273b753.jpg "} [3] = = Array (5) {[" pictitle "] = + string (7)" Title 2 "[" Piccategroy "] =&G T String (6) "Poster" ["Picauthor"] = + string (12) "Star Yao Gakuen" ["Picposttime"] + string (+) "2014-11-26 11:59:50" ["pictureurl"] = str ING ("attachment/picture/uploadify/20141126/54755027d8488.jpg"} [4] = = Array (5) {["pictitle"] + = string (33 "Synchronous write information and attachment table" ["Piccategroy"] + string (6) "poster" ["Picauthor"] + string (12) "Star Yao Gakuen" ["picposttime"] = String "2014-11-20 16:05:16" ["Pictureurl"] and "= string" attachment/picture/uploadify/20141120/ 546da0746edb8.png "} [5] = = Array (5) {[" pictitle "] = + string (33)" Synchronous write information and attachment table "[" Piccategroy "] + = string (6) "poster" ["Picauthor"] + + string (12) "Star Yao Gakuen" ["Picposttime"] + string (+) "2014-11-20 16:05:16" ["Pictureur L "] = string (" Attachment/picture/uploadify/20141120/546da0784831c.png "}}

With you this process is all merged together I want to be different title is not the same title 1 the same title of all merged together an array header 2 the same merge together an array is the picture link Pictureurl This merger to find out how to judge a lot of the title is repeated It is a header with multiple duplicate arrays, mainly to distinguish between several different headings.
Array (' pictitle ' = ' + ' Title 2, sync write information and attachment table ', ' Piccategroy ' + ' poster ', ' picauthor ' = ' star Yew Gakuen ', ' picposttime ' and ' = 2014- 11-26 11:59:50,2014-11-20 16:05:16 ', ' pictureurl ' = ' attachment/picture/uploadify/20141126/547550278b7db.jpg, attachment/picture/uploadify/20141126/54755027ab89b.jpg,attachment/picture/uploadify/20141126/ 547550273b753.jpg,attachment/picture/uploadify/20141126/54755027d8488.jpg,attachment/picture/uploadify/ 20141120/546da0746edb8.png,attachment/picture/uploadify/20141120/546da0784831c.png ',)

$ar = Array ("Pictitle" and "Title 2", "Piccategroy" + "poster", "Picauthor" and "star Yao Gakuen", "Picposttime"     = "2014-11-26 11:59:50", "pictureurl" = "attachment/picture/uploadify/20141126/547550278b7db.jpg",), Array ( "Pictitle" and "Title 2", "Piccategroy" and "posters", "Picauthor" and "Xing Yao Gakuen", "Picposttime" and "2014-11-26 1  1:59:50 "," pictureurl "=" attachment/picture/uploadify/20141126/54755027ab89b.jpg ",), Array (" pictitle "= "Title 2", "Piccategroy" and "posters", "Picauthor" and "Xing Yao Gakuen", "Picposttime" and "2014-11-26 11:59:50", "Pictur Eurl "=" and "Attachment/picture/uploadify/20141126/547550273b753.jpg", Array ("Pictitle" and "Title 2", "Piccateg Roy "=" poster "," Picauthor "and" Xing Yao Gakuen "," Picposttime "and" 2014-11-26 11:59:50 "," Pictureurl "and" Attachm " Ent/picture/uploadify/20141126/54755027d8488.jpg ","), Array ("Pictitle" and "=" synchronously write information and attachment table "," Piccategroy "and" = " Poster "," Picauthor "=> "Star Yao Gakuen", "Picposttime" and "2014-11-20 16:05:16", "Pictureurl" and "Attachment/picture/uploadify/20141120/546da07" 46edb8.png ","), Array ("Pictitle" and "=" synchronously write information and attachment table "," Piccategroy "and" posters "," Picauthor "and" Xing Yao Gakuen "," Picposttime "=" 2014-11-20 16:05:16 "," pictureurl "=" attachment/picture/uploadify/20141120/" 546da0784831c.png,), $res = Array (), foreach ($ar as $item) {if (Isset ($res [$item [' Pictitle ']]) $res [$item [' Pictitl  E ']] = $item; else $res [$item [' Pictitle ']][' pictureurl ']. = ', '. $item [' Pictureurl '];} Var_export (Array_values ($res));
Array (  0 = =   Array (' pictitle ' = ' + '    Title 2 ',    ' piccategroy ' = ' poster ',    ' picauthor ' = ' star Yao Gakuen '),    ' picposttime ' = ' 2014-11-26 11:59:50 ',    ' pictureurl ' = ' attachment/picture/uploadify/20141126/' 547550278b7db.jpg,attachment/picture/uploadify/20141126/54755027ab89b.jpg,attachment/picture/uploadify/ 20141126/547550273b753.jpg,attachment/picture/uploadify/20141126/54755027d8488.jpg ',  ),  1 =   Array (    ' pictitle ' = ' sync write information and attachment table ',    ' Piccategroy ' + ' poster ',    ' picauthor ' + ' star Yao Gakuen ',    ' Picposttime ' = ' 2014-11-20 16:05:16 ',    ' pictureurl ' + ' attachment/picture/uploadify/20141120/ 546da0746edb8.png,attachment/picture/uploadify/20141120/546da0784831c.png ',  ),)

casually wrote down, not tested, block letters is such a way of thinking

$ar = array (
Array (
"Pictitle" and "Title 1",
"piccate Groy "+",
"Picauthor" + "author", "
" picposttime "=" 2014-11-20 16:05:16 ",
" Pictureurl "+" at Tachment/picture/uploadify/20141120/546da0784831c.png ",
),
Array (
" pictitle "=" Title 1 ",
" Piccategroy "+",
"Picauthor" + "author",
"picposttime" = "2014-11-20 16:05:16",
"Pictureurl" =& Gt "Attachment/picture/uploadify/20141120/546da0746edb8.png",
),
);

//title = + Array index array
$map _arr=array ();
foreach ($ar as $key + $item)
{
//Determines whether the header is in the array index array
if (isset ($map _arr[$item [' Pictitle ']))
{ br>//In words merge
$ar [$key]=array_merge ($ar [$key], $map _arr[$item [' Pictitle ']]);
}
Else
{
//Do not store the map index
$map _arr[$item [' Pictitle ']]= $item;
unset ($ar [$key]);//Delete the original value existing in the array
}
}

Supplemented by unset ($ar [$key]); Delete the original value in the array
This sentence moved to the bottom of this, negligent write wrong
In the words of the merger
$ar [$key]=array_merge ($ar [$key], $map _arr[$item [' Pictitle ']]);

$arr = Array (    "Pictitle" and "Title 1",    "Piccategroy" and "category",    "picauthor" = "Author",    " Picposttime "=" 2014-11-20 16:05:16 ",    " pictureurl "=" attachment/picture/uploadify/20141120/" 546da0784831c.png ","  ),  Array (    "Pictitle" and "Title 1",    "Piccategroy" and "category",    "picauthor" = > "Author",    "picposttime" = "2014-11-20 16:05:16",    "Pictureurl" and "attachment/picture/uploadify/" 20141120/546da0746edb8.png ",  )), $item =array (), foreach ($arr as $key + = $value) {    foreach ($value as $k = > $v) {        if (!isset ($item [$k])) {            $item [$k]= $v;        }    } Print_r ($item);

$ar = Array ("Pictitle" and "Title 2", "Piccategroy" + "poster", "Picauthor" and "star Yao Gakuen", "Picposttime"     = "2014-11-26 11:59:50", "pictureurl" = "attachment/picture/uploadify/20141126/547550278b7db.jpg",), Array ( "Pictitle" and "Title 2", "Piccategroy" and "posters", "Picauthor" and "Xing Yao Gakuen", "Picposttime" and "2014-11-26 1  1:59:50 "," pictureurl "=" attachment/picture/uploadify/20141126/54755027ab89b.jpg ",), Array (" pictitle "= "Title 2", "Piccategroy" and "posters", "Picauthor" and "Xing Yao Gakuen", "Picposttime" and "2014-11-26 11:59:50", "Pictur Eurl "=" and "Attachment/picture/uploadify/20141126/547550273b753.jpg", Array ("Pictitle" and "Title 2", "Piccateg Roy "=" poster "," Picauthor "and" Xing Yao Gakuen "," Picposttime "and" 2014-11-26 11:59:50 "," Pictureurl "and" Attachm " Ent/picture/uploadify/20141126/54755027d8488.jpg ","), Array ("Pictitle" and "=" synchronously write information and attachment table "," Piccategroy "and" = " Poster "," Picauthor "=> "Star Yao Gakuen", "Picposttime" and "2014-11-20 16:05:16", "Pictureurl" and "Attachment/picture/uploadify/20141120/546da07" 46edb8.png ","), Array ("Pictitle" and "=" synchronously write information and attachment table "," Piccategroy "and" posters "," Picauthor "and" Xing Yao Gakuen "," Picposttime "=" 2014-11-20 16:05:16 "," pictureurl "=" attachment/picture/uploadify/20141120/" 546da0784831c.png,), $res = Array (), foreach ($ar as $item) {if (Isset ($res [$item [' Pictitle ']]) $res [$item [' Pictitl  E ']] = $item; else $res [$item [' Pictitle ']][' pictureurl ']. = ', '. $item [' Pictureurl '];} Var_export (Array_values ($res));
Array (  0 = =   Array (' pictitle ' = ' + '    Title 2 ',    ' piccategroy ' = ' poster ',    ' picauthor ' = ' star Yao Gakuen '),    ' picposttime ' = ' 2014-11-26 11:59:50 ',    ' pictureurl ' = ' attachment/picture/uploadify/20141126/' 547550278b7db.jpg,attachment/picture/uploadify/20141126/54755027ab89b.jpg,attachment/picture/uploadify/ 20141126/547550273b753.jpg,attachment/picture/uploadify/20141126/54755027d8488.jpg ',  ),  1 =   Array (    ' pictitle ' = ' sync write information and attachment table ',    ' Piccategroy ' + ' poster ',    ' picauthor ' + ' star Yao Gakuen ',    ' Picposttime ' = ' 2014-11-20 16:05:16 ',    ' pictureurl ' + ' attachment/picture/uploadify/20141120/ 546da0746edb8.png,attachment/picture/uploadify/20141120/546da0784831c.png ',  ),)



Thank you moderator adult solved only the last of this var_export function removal is what I want the result ~
  • 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.