php对数组中的值进行排序
案例
<?php
$a = array('1124','1125','1126');
$s1 = 1124;
$s2 = 1125;
$ks1 = array_search($s1,$a);
$ks2 = array_search($s2,$a);
$a[$ks1] = $s2;
$a[$ks2] = $s1;
print_r($a);
?>
应用
$current_id = $this->_request('current_id','intval'); // 当前值
$exchange_id = $this->_request('exchange_id','intval'); // 替换值
$current_key = array_search($current_id,$category_content_arr);
$exchange_key = array_search($exchange_id,$category_content_arr);
$category_content_arr[$exchange_key] = $current_id;
$category_content_arr[$current_key] = $exchange_id;
$data['content'] = serialize($category_content_arr);
$data['id'] = $category_id;
$res = $mallCategoryModel->save($data);
if ($res !== FALSE) {
echo "1"; // 排序成功
} else {
echo "2"; // 排序失败
}