zoukankan      html  css  js  c++  java
  • 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"; // 排序失败
    }
    
    

  • 相关阅读:
    java--exceptions
    java-interface
    Java笔记
    memcpy
    const 关键字
    LeeCode整数 反转
    函数调用运算符笔记
    cvCreateImage
    c++继承笔记1
    虚拟机下的debian无法登陆
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/5311347.html
Copyright © 2011-2022 走看看