The method I used was to distinguish blocks by key, then assign the blocks to other variables, and then perform some operations. This used a lot of for and foreach, and the amount of code was also large, so it was returned.
After the above guidance, I found that it is really simple, and now I will share it with you.
ID |
FIELD1 |
FIELD2 | FIELD3 | FIELD4 |
Key |
1 |
*** | *** | *** | *** | meat1 |
2 |
*** | *** | *** | *** | meat1 |
3 |
*** | *** | *** | *** | meat1 |
4 | *** | ** * | *** | *** | meat1 |
5 |
*** | *** | *** | *** | fruit2 |
6 | *** | *** | *** | *** | fruit2 |
7 |
*** | *** | *** | *** | fruit2 |
8 |
*** | *** | *** | *** | fruit2 |
9 |
*** | *** | *** | *** | fruit2 |
10 |
*** | *** | *** | *** | food3 |
11 |
*** | *** | *** | *** | food3 |
Now there is the result shown above
Requirement: To operate on this array that has been sorted by key, items with the same key for processing.
Tips: This is a very typical structure of a parent-child table, which means it is actually a merger of two tables. It can be processed into two arrays to facilitate block operations in the array
array1:ID|Key
ID |
Key |
1 |
meat1 |
2 | meat1 |
3 |
meat1 |
4 | meat1 |
5 |
fruit2 |
6 | fruit2 |
7 |
fruit2 |
8 | fruit2 |
9 |
fruit2 |
10 |
food3 |
11 |
food3 |
array2:key => array(ID,FIELD1,FIELD2,FIELD3,FIELD4,FIELD5,Key)
ID |
FIELD1 |
FIELD2 | FIELD3 | FIELD4 |
Key |
|
meat1=> |
2 | *** | *** | *** | *** | meat1 |
3 | *** | *** | *** | meat1 | ||
4 |
*** |
*** | *** | *** | meat1 | |
5 | *** | *** | *** | *** | fruit2 | |
6 |
*** |
*** | *** | *** | fruit2 | |
7 | *** | *** | *** | *** | fruit2 | |
8 | *** | * ** | *** | fruit2 | ||
9 | *** | *** | *** | fruit2 | ||
10 | *** | *** | *** | *** | food3 | |
11 |
*** | *** | *** | *** | food3 | |
Implement the above array separation code | After this, it is very convenient to access the block data of tempArrayforeach($tempArray as $row){ | array1[$row[' ID']] = $row['Key']; | array2[$row['Key']][] = $row; | } | Access and processing code |
The above introduces the classic examples of Windows XP hardware optimization and PHP code optimization, including the content of Windows XP hardware optimization. I hope it will be helpful to friends who are interested in PHP tutorials.