Home > Backend Development > PHP Tutorial > Example of function to increase points in php json

Example of function to increase points in php json

WBOY
Release: 2016-07-25 09:00:28
Original
939 people have browsed it
A piece of PHP code that implements JSON to increase points is very helpful for mastering how to construct JSON data in PHP. Friends in need can refer to it.

The code is as follows, for learning reference only.

 function zeng_integral(){  
  $jifen=& m('integral');  
  /*判断网吧*/  
  $store=isset($store_id)?intval($store_id):0;  
  $injifen=$jifen->get(array('user_id'=>$_SESSION['user_info']['user_id']));  
  $yanzhen=json_decode($injifen['integrallog'],true);  
   
  if(isset($injifen)){  
    $arrstore=array();  
    foreach ($yanzhen as $k=>$v){  
   $arrstore[]=$v['store_id'];  
    }  
    /*判断积分是否存在如果存*/  
    if (in_array($store,$arrstore)) {  
   foreach ($yanzhen as $key=>$val){  
   $yanzhen[$key]['store_id']=$key;  
   $yanzhen[$key]['jifen']=$val['jifen']+5;  
   }  
   $integral=json_encode($yanzhen);  
    }else {  
   foreach ($yanzhen as $key=>$val){  
     $yanzhen[$store]['store_id']=$store;  
     $yanzhen[$store]['jifen']=1;  
     }  
     $integral=json_encode($yanzhen);  
    }  
    /*构造数据*/  
    $data=array(  
   'integrallog'=>$integral,   
     );  
    $integ=$jifen->edit($injifen['id'],$data);  
     if ($integ) {  
    return true;  
     }  
  }else {  
  /*构造数组*/  
  $config=array();  
  $config[$store]['store_id']=$store;  
  $config[$store]['jifen']=1;  
  $integral=json_encode($config);  
  /*构造数据*/  
  $data=array(  
   'user_id'=>$_SESSION['user_info']['user_id'],  
   'integrallog'=>$integral,   
  );  
  $integ=$jifen->add($data);  
  if ($integ) {  
   return true;  
  }  
  }  
}  
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template