I have an array like this
SKU color image 11 black image 1 11 black image 2 11 black image 3 12 red image 4 12 red image 5
I want to merge the image into a value for each record like this
SKU color image 11 black image 1, image 2, image 3 12 red image 4, image 5
here is a var dump
array (size = 3886) ) 0 = & gt; Array (size = 4) 0 = & gt; String 'Group SKU' (Length = 9) 1 = & gt; String 'color' (length = 5) 2 = & gt; String 'sort' (length = 4) 3 = & gt; String 'FILENAME' (length = 8) 1 = & gt; Array (size = 4) 0 = & gt; String '100710 9' (length = 7) 1 = & gt; String 'black' (length = 5) 2 = & gt; String '1' (length = 1) 3 = & gt; String '11 .jpg '(length = 6) 2 = & gt;
Any help
Try it -
11, 'color' =>, 'black', ' Image '=' Gtc: 'gtc:; array (' SKU '=> 11,' color '=>,' black ',' image '=>' image 3 '),' 3 '= & Array ('SKU' = & gt; 12, 'color' = & gt; red ',' image '=> 4' '),' 4 '= & gt; array (' SKU '=' > '5' => Array ('SKU' => 13, 'Colors' =>,' Colors' = & gt; 12, 'Colors' = & gt; Red', 'Image' = & gt; = & Gt; Orange ',' image '= & gt;' image 6 '),' 6 '=> array (' SKU '=> 13,' color '=> orange', 'image '= & Gt;' Image 7 ')); Echo "prefix"; print_r ($ my_Array); $ NewArray = array (); Vide She Merge ($ my_Array $ key as = key = & gt; $ value) {if ($ key == 0) {$ newArray [] = $ value;} Else {foreach ($ newArray $ k = & gt; $ val ) {If ($ value ['SKU'] == $ val ['SKU'] & amp; $ value ['color'] == $ val ['color']) {$ check = 1; $ NewArray [$ K] ['image'] = intestine (',', array ($ val ['image'], $ value ['image'])); break; } And {$ check = 0; }} If (trim ($ check) == 0) {$ newArray [] = $ value; }}} Echo "& lt; east / & gt;"; Print_r ($ newArray); ? & Gt;
Output:
No comments:
Post a Comment