The problem is why foreach only runs once at a time. If a batch of data is processed, the first one will be processed properly. The system will not move. Run: convert $ one of the following data to $ two. Delete $ one on the left. Add if $ two is not added on the right, and add If yes. Staff_depa... the question is why foreach only runs once at a time.
If a batch of data is processed, the first one will be processed properly. The system will not move.
Run the following command:
Convert $ one from the following data to $ two.
Delete $ one on the left. Add if $ two is not added on the right, and add If yes.
The data structure of staff_departmentid is as follows:
7-8-9-6
6-7-9
8-9-10-6
8-9
$ One = I ('Post. one '); $ two = I ('Post. two '); $ m = M ('staff '); // first, find the value to be modified on the left. $ conone ['staff _ inclumentid'] = array ('like', "% ". $ one. "%"); $ list = $ m-> where ($ conone)-> select (); foreach ($ list as $ key => $ value) {$ arr = explode ('-', $ value ['staff _ shortmentid']); $ array_key = array_search ($ one, $ arr ); unset ($ arr [$ array_key]); // redesign the index $ arr = array_values ($ arr); $ nowstr = implode ('-', $ arr ); // first subtract the $ one value $ w1 ['staff _ id '] = $ Value ['staff _ id']; $ data ['staff _ 1_mentid'] = $ nowstr; $ jian = $ m-> where ($ w1) -> save ($ data); // If $ two value already exists, no value is added. $ Array2_key = array_search ($ two, $ arr); if ($ array2_key | $ array2_key = 0) {// do not add} else {// If NO, add a $ arr [] = $ two; $ arr = array_values ($ arr ); $ addstr = implode ('-', $ arr); $ adddata ['staff _ inclumentid'] = $ addstr; $ w2 ['staff _ id'] = $ value ['staff _ id']; $ jia = $ m-> where ($ w2) -> save ($ adddata );}}
Reply content:
The problem is why foreach only runs once at a time.
If a batch of data is processed, the first one will be processed properly. The system will not move.
Run the following command:
Convert $ one from the following data to $ two.
Delete $ one on the left. Add if $ two is not added on the right, and add If yes.
The data structure of staff_departmentid is as follows:
7-8-9-6
6-7-9
8-9-10-6
8-9
$ One = I ('Post. one '); $ two = I ('Post. two '); $ m = M ('staff '); // first, find the value to be modified on the left. $ conone ['staff _ inclumentid'] = array ('like', "% ". $ one. "%"); $ list = $ m-> where ($ conone)-> select (); foreach ($ list as $ key => $ value) {$ arr = explode ('-', $ value ['staff _ shortmentid']); $ array_key = array_search ($ one, $ arr ); unset ($ arr [$ array_key]); // redesign the index $ arr = array_values ($ arr); $ nowstr = implode ('-', $ arr ); // first subtract the $ one value $ w1 ['staff _ id '] = $ Value ['staff _ id']; $ data ['staff _ 1_mentid'] = $ nowstr; $ jian = $ m-> where ($ w1) -> save ($ data); // If $ two value already exists, no value is added. $ Array2_key = array_search ($ two, $ arr); if ($ array2_key | $ array2_key = 0) {// do not add} else {// If NO, add a $ arr [] = $ two; $ arr = array_values ($ arr ); $ addstr = implode ('-', $ arr); $ adddata ['staff _ inclumentid'] = $ addstr; $ w2 ['staff _ id'] = $ value ['staff _ id']; $ jia = $ m-> where ($ w2) -> save ($ adddata );}}