Array processing is such a one-dimensional array, how to turn it into a multi-dimensional array according to shop name, color, size specifications in turn?
Reply to discussion (solution)
Write a getAll function and a query function in the encapsulated MySQL class.
Public function getAll ($ SQL)
{
$ Rs = $ this-> query ($ SQL );
$ List = array ();
If (! $ Rs)
{
Return false;
}
Else {
While ($ row = mysql_fetch_assoc ($ rs ))
{
$ List [] = $ row;
}
Return $ list;
}
}
Public function query ($ SQL)
{
Return mysql_query ($ SQL, $ this-> conn); // $ this-> conn is the resource variable used to connect to the database.
}
Initialize an object outside the class, write three SQL statements to get three columns, and send the SQL statement using the getAll function to obtain the result, finally, you can write an array into the query result... I don't want to write too much encapsulated class content. I don't know if I can help you --
$array=array(array('CKMC'=>'store1','GG1MC'=>'color1','GG2MC'=>'size1'),array('CKMC'=>'store1','GG1MC'=>'color1','GG2MC'=>'size2'),array('CKMC'=>'store1','GG1MC'=>'color2','GG2MC'=>'size1'),array('CKMC'=>'store1','GG1MC'=>'color2','GG2MC'=>'size2'),array('CKMC'=>'store2','GG1MC'=>'color1','GG2MC'=>'size1'),array('CKMC'=>'store2','GG1MC'=>'color2','GG2MC'=>'size2'),);$array2=array();foreach($array as $val){if(array_key_exists($val['CKMC'],$array2)){if(array_key_exists($val['GG1MC'],$array2[$val['CKMC']])){$array2[$val['CKMC']][$val['GG1MC']][]=$val;}else $array2[$val['CKMC']][$val['GG1MC']]=array($val);}else $array2[$val['CKMC']]=array($val['GG1MC']=>array($val));}echo '';print_r($array2);echo '
';