Two-dimensional array sort function

xiaoxiao2021-03-06  97

// The data structure is as follows:

$ Products = Array (

ARRAY

fb_babrand => "

Del

"

FB_BAMODEL => "55506"

),

ARRAY

fb_babrand => "

Del

"

FB_BAMODEL => "56535"

),

ARRAY

FB_babrand => "HP",

Fb_bamodel => "f1382a"

)

);

// The data is processed as follows:

$ Products = Array

(

[0] => Array

(

[fb_babrand] =>

Del

[FB_BAMODEL] => 55506, 56535

)

[1] => Array

(

[fb_babrand] => HP

[fb_bamodel] => f1382a

)

)

Function Groupbrand ($ Products, $ Group, $ JOIN) {

/ **

* This function classifies $ group in a specified 2D array $ Products to connect the same $ group $ join value.

* @ Parameters: $ PRODUCTS, $ Group, $ JOIN, where $ Products contains data to be operated

* @ Return: Returns a two-dimensional array $ RESULT, arrays include two keynames: $ group, $ JOIN

* /

$ out = array ();

Foreach ($ Products AS $ V) {

$ key = $ V [$ group];

$ Value = $ V [$ JOIN];

IF (Isset ($ OUT [$ Key])))

$ OUT [$ Key]. = ", $ value";

Else

$ OT [$ key] = "$ value";

}

$ result = array ();

Foreach ($ OUT AS $ K => $ V)

$ Result [] = Array ($ group => $ k, $ join => $ V);

Return $ Result;

}

转载请注明原文地址:https://www.9cbs.com/read-122100.html

New Post(0)