i_array_column和_curl 和 json2array自定义函数
来源:互联网 发布:阿里云 安全组规则 编辑:程序博客网 时间:2024/05/19 00:36
/** * tp中实现array_column的功能 */function i_array_column($input, $columnKey, $indexKey=null){ if(!function_exists('array_column') || is_array($columnKey)){ $columnKeyIsNumber = (is_numeric($columnKey)) ? true : false; $indexKeyIsNull = (is_null($indexKey)) ? true : false; $indexKeyIsNumber = (is_numeric($indexKey)) ? true : false; $result = array(); foreach((array)$input as $key=>$row){ if($columnKeyIsNumber){ //如果是数字索引 $tmp= array_slice($row, $columnKey, 1); $tmp= (is_array($tmp) && !empty($tmp))?current($tmp):null; }else{ //判断是多列还是单列还是全部列 //是数组且长度大于1 if( is_array( $columnKey ) ){ if( count( $columnKey ) > 1 ){ foreach ($columnKey as $tmpKey) { $tmp[$tmpKey] = $row[$tmpKey]; } } else { //是数组但长度不大于1的时候直接将其取出 $columnKey = array_shift( $columnKey ); } } if ( is_string( $columnKey ) ){ $tmp= isset($row[$columnKey])?$row[$columnKey]:null; } else if ( is_null( $columnKey ) ){ $tmp = $row; } } if(!$indexKeyIsNull){ if($indexKeyIsNumber){ $key = array_slice($row, $indexKey, 1); $key = (is_array($key) && !empty($key))?current($key):null; $key = is_null($key)?0:$key; }else{ $key = isset($row[$indexKey])?$row[$indexKey]:0; } } $result[$key] = $tmp; } return $result; }else{ return array_column($input, $columnKey, $indexKey); }}
/** * 模拟请求,兼容post和get */function _curl($URL = '', $post_data = array(),$timeout=0){ $cu = curl_init(); if($post_data){ curl_setopt($cu, CURLOPT_POST, 1);//post提交方式 curl_setopt($cu, CURLOPT_POSTFIELDS, $post_data);//post提交的数据 } curl_setopt($cu, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($cu, CURLOPT_URL, $URL); curl_setopt($cu, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);//在发起连接前等待的时间,如果设置为0,则无限等待。 $response = curl_exec($cu); curl_close($cu); return $response;}
/** * 模拟请求,兼容get,post,put,delete * @param string $url * @param string $param * @param string $header * @return mixed */ public function _curl($url,$method='get',$param='', $header='') { $method=strtoupper($method); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); //抓取指定网页 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //要求结果为字符串且输出到屏幕上 curl_setopt($ch, CURLOPT_HTTPHEADER, $header); // 增加 HTTP Header(头)里的字段 curl_setopt ( $ch, CURLOPT_HEADER, true ); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 终止从服务端进行验证 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); if($method == 'POST'){ curl_setopt($ch, CURLOPT_POST, 1); //post请求 curl_setopt($ch, CURLOPT_POSTFIELDS, $param); } if($method =='PUT'){ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); //put请求 curl_setopt($ch, CURLOPT_POSTFIELDS, $param); } if($method =='DELETE'){ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); //delete请求 } $data = curl_exec($ch); curl_close($ch); return $data; }
//获取json参数 protected function json2array() { $input = file_get_contents('php://input');// file_put_contents('log.html', $input); $input = urldecode($input); $input = substr($input, strpos($input, '{')); file_put_contents('log.html', $input); $data = json_decode($input, true); return $data; }
0 0
- i_array_column和_curl 和 json2array自定义函数
- MySQL 自定义和函数
- 调用函数和自定义函数
- 宏函数和自定义函数
- 加密函数和自定义函数
- QT 自定义函数 自定义信号和槽
- QT 自定义函数 自定义信号和槽
- Mysql中的自定义函数和自定义过程
- QT 自定义函数 自定义信号和槽
- VB自定义函数加 ""和 "";
- 自定义存储过程和函数
- Freemaker 自定义指令和函数
- 自定义存储过程和函数
- MySql--索引和自定义函数
- 5.内置函数和自定义函数
- 宏函数和自定义函数的区别
- HIVE中的自定义函数(临时函数和永久函数)
- vfp如何自定义函数和过程
- Cocos2d-x中使用第三方so库
- Android中Context详解 ---- 你所不知道的Context
- APACHE COMMONS LOGGING
- C++ 7.8.4 实参类型转换(没有看完!)
- easyui 扩展
- i_array_column和_curl 和 json2array自定义函数
- Oracle学习笔记(10)----------- 约束
- PHP静态成员变量和非静态成员变量
- Unity3D & Java 基于 Protobuf 通信实现
- Android——ViewPager多页面滑动切换以及动画效果
- Doxygen - 分析代码结构的好帮手
- PDU编码(非常经典)
- 使用纹理通过glUniform1i
- Android 进阶 教你打造 Android 中的 IOC 框架 【ViewInject】 (上)