Issues related to array processing

Source: Internet
Author: User
Problems with array processing

Such a one-dimensional array, how to get him in order according to the store name, color, size of a multidimensional array?
------to solve the idea----------------------
Write a getall function and a query function in the package 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 a resource variable that connects to a database
}
Initialize an object outside the class, and then write three SQL statements to get three columns, the SQL statement through the GetAll function to get results, the final query results to write their own number of groups put in ... Encapsulation class content too much will not write, do not know whether can help the landlord--
------to solve the idea----------------------

$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 '),
);

$array 2=array ();
foreach ($array as $val)
{
if (array_key_exists ($val [' CKMC '], $array 2))
{
if (array_key_exists ($val [' GG1MC '], $array 2[$val [' CKMC ']])
{
$array 2[$val [' CKMC ']][$val [' GG1MC ']][]= $val;
}
else $array 2[$val [' CKMC ']][$val [' GG1MC ']]=array ($val);
}
else $array 2[$val [' CKMC ']]=array ($val [' GG1MC ']=>array ($val));
}
Echo '
';
Print_r ($array 2);
Echo '
';
  • 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.