Phpfor loop ideas

Source: Internet
Author: User
I am a beginner in PHP. I recently developed a project to receive the binary tree system welfare award. After writing, the execution efficiency is too low. Please give me some advice .! IMG (img.ask.csdn.netupload2015011714214801__636510.png) 1. if the performance reaches, it is the supervisor. Under the management system, two supervisors are managers. Under the management system, two managers are directors. 0 members, 1 supervisor, 2 managers, 3 directors. The code I wrote is as follows: The Welfare Award starts unset ($ map); the map variable value $ map [& #39; _ string & #39;] & qu phpfor

I am a beginner in PHP. I recently developed a project to receive the binary tree system welfare award. After writing, the execution efficiency is too low. Please give me some advice.
1. if the performance reaches, the supervisor will be responsible. Under the management system, two supervisors are managers. Under the management system, two managers are directors. 0 members, 1 supervisor, 2 managers, 3 directors.
The code I wrote is as follows:
// Welfare award starts
Unset ($ map); // destroy the map variable value
$ Map ['_ string'] = "datediff (curday,'". $ beginday. "') <= 0 ";
// Query the performance of all members
$ Hyyjlist = $ hyyj-> where ($ map)-> field ('userid, sum (leftyj1) + sum (leftyj2) as sumleft ')-> group ('userid ') -> select ();
$ GlrCountArry = array (); // key: Supervisor name + flw.l value: number of supervisors saved array
Foreach ($ hyyjlist as $ hkey => $ hvalue) {// cyclically update your supervisor benefits
If ($ hvalue ['sumleft']> = 10000 ){
$ Us = $ userListArry [$ hvalue ['userid']; // 3 Get a member by ID
If ($ us ['flstate'] = 0) {// The status is 0 Member
If ($ salary1-> where (array ('periods '=> $ periods, 'userid' => $ us ['id']) -> setField (array ('flj' => 'Z supervisor content Z') = false ){
$ Salary-> rollback ();
$ This-> error ('welfare Award update failed ');
}
For (! Empty ($ us ['gluser']), $ I = 0; $ I if (! Array_key_exists ($ us ['gluser']. "flrzg", $ glrCountArry )){
$ GlrCountArry [$ us ['gluser']. "flrzg"] = 1;
} Else {
$ GlrCountArry [$ us ['gluser']. "flrzg"] + = 1;
}
$ Us = $ userNameListArry [$ us ['gluser'];
If (empty ($ us )){
$ I = count ($ userlist );
}
}
}
}
}
$ Find ['state'] = array ('EQ ', 1); // status = 1 activated
$ Find ['_ string'] = "from_unixtime (confirmtime,' % Y-% m-% d') $ list2 = $ users-> where ($ find) -> select (); // query the member list
$ GlrCountArry2 = array (); // key: Manager name + flw.l value: number of people saves the number of managers array
Foreach ($ list2 as $ key => $ value) {// Get manager benefits
$ Us = $ value;
If ($ us ['flstate'] = 1 ){
For (! Empty ($ us ['gluser']), $ I = 0; $ I if ($ glrCountArry [$ us ['username']. "flrzg"]> 0) {// The member is at the supervisor level. the number of supervisors is greater than 0. update the member's manager benefits.
If ($ salary1-> where (array ('periods '=> $ periods, 'userid' => $ us ['id']) -> setField (array ('flj' => 'Z manager content Z') = false ){
$ Salary-> rollback ();
$ This-> error ('welfare Award update failed 2 ');
}
}
If (! Array_key_exists ($ us ['gluser']. "flw.l", $ glrCountArry2) {// enables upper-level managers of members to + 1
$ GlrCountArry2 [$ us ['gluser']. "flw.l"] = 1;
} Else {
$ GlrCountArry2 [$ us ['gluser']. "flrjl"] + = 1;
}
$ Us = $ userNameListArry [$ us ['gluser'];
If (empty ($ us )){
$ I = count ($ userlist );
}
}
} Else if ($ value ['flstate'] = 0) {// The member level is not the supervisor. the number of supervisors is greater than 1. update the manager benefits of the member.
For (! Empty ($ us ['gluser']), $ I = 0; $ I if ($ glrCountArry [$ us ['username']. "flrzg"]> 1) {// The member is at the supervisor level. the number of supervisors is greater than 0. update the member's manager benefits.
If ($ salary1-> where (array ('periods '=> $ periods, 'userid' => $ us ['id']) -> setField (array ('flj' => 'Z manager content Z') = false ){
$ Salary-> rollback ();
$ This-> error ('welfare Award update failed 2 ');
}
}
If (! Array_key_exists ($ us ['gluser']. "flw.l", $ glrCountArry2) {// enables upper-level managers of members to + 1
$ GlrCountArry2 [$ us ['gluser']. "flw.l"] = 1;
} Else {
$ GlrCountArry2 [$ us ['gluser']. "flrjl"] + = 1;
}
$ Us = $ userNameListArry [$ us ['gluser'];
If (empty ($ us )){
$ I = count ($ userlist );
}
}

} Foreach ($ list2 as $ key => $ value) {// Get Director benefits $ us = $ value; if ($ us ['flstate'] = 2) {// The status is 2 manager (! Empty ($ us ['gluser']), $ I = 0; $ I
   
    
0) {// The member is at the manager level. the number of managers in the array is greater than 0. update the member's director benefits if ($ salary1-> where (array ('periods '=> $ periods, 'userid' => $ us ['id'])-> setField (array ('flj' => 'Z director award content Z') = false) {$ salary-> rollback (); $ this-> error ('welfare Award update failed 3 ');}} $ us = $ userNameListArry [$ us ['gluser']; if (empty ($ us) {$ I = count ($ userlist );}}} else if ($ value ['flstate'] <2) {// The status is not a manager. as long as the number of managers in the array reaches 2, the supervisor benefits (! Empty ($ us ['gluser']), $ I = 0; $ I
    
     
1) {// The member is a manager. the number of managers in the array is greater than 1. update the member's director benefits if ($ salary1-> where (array ('periods '=> $ periods, 'userid' => $ us ['id'])-> setField (array ('flj' => 'Z director award content Z') = false) {$ salary-> rollback (); $ this-> error ('welfare Award update failed 3 ');}} $ us = $ userNameListArry [$ us ['gluser']; if (empty ($ us) {$ I = count ($ userlist );}}}} // welfare award ended
    
   
Related Article

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.