我有部门列表,每个部门都有一个UP按钮和另一个按钮DOWN
单击向上按钮时,它会调用该功能..
Public function actionUP($id, $sort_order){
$allDeps = Department::model()->findAll($criteria);
$depArr = array();
foreach ($allDeps as $department){
$temp = array();
$temp['id'] = $department->id;
$temp['sort_order'] = $department->sort_order;
$depArr[] = $temp;
}
现在如果我var转储这个数组depArr
我得到一个数组..
array (size=17)
0 =>
array (size=2)
'id' => string '142' (length=3)
'sort_order' => string '1' (length=1)
1 =>
array (size=2)
'id' => string '141' (length=3)
'sort_order' => string '2' (length=1)
2 =>
array (size=2)
'id' => string '144' (length=3)
'sort_order' => string '5' (length=1)
3 =>
array (size=2)
'id' => string '140' (length=3)
'sort_order' => string '6' (length=1)
4 =>
array (size=2)
'id' => string '139' (length=3)
'sort_order' => string '3' (length=1)
5 =>
array (size=2)
'id' => string '143' (length=3)
'sort_order' => string '4' (length=1)
我有部门列表,职位实际上是sort_order
,并且有针对部门的向上和向下按钮,向上调用actionUP
按钮调用up?id=143&sort_order=4
如果用户点击位置4的向上按钮,其位置应更改为3,3处的部门应更改为4并且还更新为数据库..
我正在使用Yii 1.1 PHP框架
答案 0 :(得分:0)
<强> 流速: 强>
array_search('whateverID',array_column($ depArr,'id'));
array_search($ depArr [x] ['sort_order'] - 1,array_column($ depArr, 'SORT_ORDER'));