PHP面试基础之Array Functions

array_change_key_case:      把数组中所有键名称修改小写或大写,默认小写    2.array_chunk(array $array,int $size [, bool $preserve_keys=false])     把一个数组拆分成多个,第三个参数为true表示保留原来的键名    3.array_column(array $input,mixed $column_key [,$index_key=null)     返回数组中的单列,$column_key指返回哪列,$index_key如果设置了返回数组以其对应的值为返回数组的键    4.array_combile(array $keys,array $values)         数组结合    5.array_count_values(array $array)     计算数组内每个值的次数    6.array_diff_assoc ( array $array1 , array $array2 [, array $… ] ) 带索引计算数组的差集,返回$array1中有而$array2后面数组中没有的内容  7. array_diff_key ( array $array1 , array $array2 [, array $… ] ) 用键计算数组差集,返回一个数组,其key在$array1中存在,而在其他参数数组中不存在 8.array_diff_uassoc ( array $array1 , array $array2 [, array $… ], callable$key_compare_func ) 用用户提供的回调函数带索引计算数组的差集 9. array_diff_ukey ( array $array1 , array $array2 [, array $… ], callable$key_compare_func ) 用回调函数对键比较计算数组差集  10 array_diff ( array $array1 , array $array2 [, array $… ] ) 计算数组差集,返回在$array1中出现而在其他数组中不出现的数组,与array_diff_assoc区别在于不考虑索引 11.array array_fill_keys ( array $keys , mixed $value ) 用$keys的值作为key,$value的值作为值返回新数组,如果$value是关联数组,则全部返回作为值 12.array array_fill ( int $start_index , int $num , mixed $value ) 用$value的值填充长度为$num的数组,index从$start_index开始,如果$start_index是负数,则第一个键是$start_index,后面从0开始 13.array array_filter ( array $array [, callable $callback [, int $flag = 0 ]] ) 用回调函数迭代过滤数组中的元素,如果不提供callback那么$array中值为false的都将被移除。flag默认是0表示只传递值比较,如果flag是ARRAY_FILTER_USE_KEY,那么只传递key给callback,如果是ARRAY_FILTER_USE_BOTH,那么key和value都传递

TP3.1迁移PHP7.2问题及解决办法

tp3.1程序放到php7.2环境下跑会直接报functions.php下112行未找到模块的错误,原因是preg_replace函数pattern中带/e在php7之后已经被移除不再支持 解决办法是用preg_replace_callback函数代替  其中涉及到的类有  ThinkTemplate.class.php  Dispatcher.class.php  common.php  下面贴出完整代码。 ThinkTemplate.class.php: <?php // +———————————————————————- // | ThinkPHP [ WE CAN DO IT JUST THINK IT ] // +———————————————————————- // | Copyright (c) 2006-2012 http://thinkphp.cn All rights reserved. // +———————————————————————- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +———————————————————————- // | Author: liu21st <liu21st@gmail.com> // +———————————————————————- /**  * ThinkPHP内置模板引擎类  * 支持XML标签和普通标签的模板解析  * 编译型模板引擎 支持动态缓存  * @category   Think  * @package  Think  * @subpackage  Template  * @author liu21st <liu21st@gmail.com>  */ class  ThinkTemplate {     // 模板页面中引入的标签库列表     protected   $tagLib          =   array();     // 当前模板文件     protected   $templateFile    =   '';     // 模板变量     public      $tVar            =   array();     public      $config          =   array();     private     $literal         =   array();     private     $block           =   array();     /**      * 架构函数      * @access public      */     public function __construct(){         $this->config['cache_path']         =   C('CACHE_PATH');         $this->config['template_suffix']    =   C('TMPL_TEMPLATE_SUFFIX');         $this->config['cache_suffix']       =   C('TMPL_CACHFILE_SUFFIX');         $this->config['tmpl_cache']         =   C('TMPL_CACHE_ON');         $this->config['cache_time']         =   C('TMPL_CACHE_TIME');         $this->config['taglib_begin']       =   $this->stripPreg(C('TAGLIB_BEGIN'));         $this->config['taglib_end']         =   $this->stripPreg(C('TAGLIB_END'));         $this->config['tmpl_begin']         =   $this->stripPreg(C('TMPL_L_DELIM'));         $this->config['tmpl_end']           =   $this->stripPreg(C('TMPL_R_DELIM'));         $this->config['default_tmpl']       =   C('TEMPLATE_NAME');         $this->config['layout_item']        =   C('TMPL_LAYOUT_ITEM');     }     private function stripPreg($str) { … Read more

lnmp安装Tp5报500和404问题解决

lnmp为了防止跨目录访问在程序跟目录创建.user.ini,而tp5安装在lnmp创建时配置的时程序目录下的public文件夹,这样会导致其无法访问public的上层目录 解决办法时进入到lnmp的文件夹工具类   cd /root/lnmp1.5/tools 运行如下命令 ./remove_open_basedir_restriction.sh 选择要移除限制的目录 比如 /home/repository/va/public 然后cd到/home/repository/va/public目录 删除.user.ini 再次访问  就正常了

centos7.2 安装xdebug

下载 到官网下载源码  https://xdebug.org/download.php cd /wwwroot https://xdebug.org/files/xdebug-2.7.0alpha1.tgz 2.解压安装 mkdir xdebug   #创建目录 cp xdebug-2.7.0alphal.tgz –target-directory=./xdebug  #拷贝到创建目录 cd xdebug  #进入目录 tar -xvf xdebug-2.7.0alphal.tgz  #解压 cd xdebug-2.7.0alphal  /usr/local/php/bin/php -m  #查看是否已经看装模块  /usr/local/php/bin/phpize ./configure –with-php-config=/usr/local/php/bin/php-config make && make instal #编译安装 3.安装成功会提示 Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/   +———————————————————————-+   |                                                                      |   |   INSTALLATION INSTRUCTIONS                                          |   |   =========================                                          |   |                                                                      |   |   See http://xdebug.org/install.php#configure-php for instructions   |   |   on how to enable Xdebug for PHP.                                   |   |                                                                      |   |   Documentation is available online as well:                         |   |   – A list of all settings:  http://xdebug.org/docs-settings.php     |   |   – A list of all functions: http://xdebug.org/docs-functions.php    |   |   – Profiling instructions:  http://xdebug.org/docs-profiling2.php   |   |   – Remote debugging:        http://xdebug.org/docs-debugger.php     |   |                                                                      |   |                                                                      |   |   NOTE: Please disregard the message                                 |   |       You should add "extension=xdebug.so" to php.ini                |   |   that is emitted by the PECL installer. This does not work for      |   |   Xdebug.                                                            |   |                                                                      |   +———————————————————————-+ 4.php.ini添加扩展    cd /usr/local/php/etc  vim php.ini   #最后一行写入    [xDebug] zend_extension = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so" 5.  echo phpinfo();查看

PHP7.2+ each,count函数替代方法

each  这个函数在php7.2以后就弃用了  替代方法: function func_new_each(&$array){     $res = array();     $key = key($array);     if($key !== null){         next($array);         $res[1] = $res['value'] = $array[$key];         $res[0] = $res['key'] = $key;     }else{         $res = false;     }     return $res; } 实例: while (list ($key, $val) = $this->func_new_each($para)) {    if($key == "sign" || $key == "sign_type" || $val == "")continue;    else    $para_filter[$key] = $para[$key]; } 2. count  这个函数没有弃用,但是在7.2+上传递一个字符串参数的时候会报错:Warning:  count(): Parameter must be an array or an object that implements Countable 替代方法: function func_new_count($array_or_countable,$mode = COUNT_NORMAL){     if(is_array($array_or_countable) || is_object($array_or_countable)){         return count($array_or_countable, $mode);     }else{         return 0;     } }

中华人民共和国行政区划数据库/爬虫

包含中国省、市、县、街道、村/居委会5级数据(港、澳、台除外(统计局官网没有给出)),数据来源为国家统计局。 程序基于tp3.2.3编写,依赖Querylist3。 主要代码: /**  * @author Adam  * Time: 2018/6/15 14:50  */ public function sheng() {     $data = QueryList::Query($this->baseurl . "index.html", array("url" => array("td>a ", "href"), "name" => array("td>a", "text")), "", 'UTF-8', 'GB2312')->getData();     foreach ($data as $k => $v) {         $data[$k]["url"] = str_replace(".html", "", $v["url"]);         $data[$k]["saveid"] = $this->generate_full_id($data[$k]["url"]);         $res = $this->areamodel->where(array("area_id" => $data[$k]["url"]))->find();         if (empty($res)) {             $this->areamodel->data(array("area_id" => $data[$k]["url"], "area_pid" => 0, "area_name" => $data[$k]["name"], "level" => 1))->add();         }     }     echo json_encode($data);     die; } /**  * 二级 市   http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/14.html  * @author Adam  * Time: 2018/6/20 13:43  */ public function secondway() {     $toplevel = $this->areamodel->where(array("imported" => 0, "level" => 1))->order("area_id DESC")->find();     if (empty($toplevel)) {         echo "全部导入完毕,无需重新导入";         die;     }     $fatherid = $toplevel["area_id"];     $url = $this->baseurl . $toplevel["area_id"] . ".html";     $data = QueryList::Query($url, array("url" => array("td:eq(0)>a", "href"), "name" => array("td:eq(1)>a", "text")), "tr.citytr", 'UTF-8', 'GB2312')->getData();     foreach ($data as $k => $v) {         $data[$k]["url"] = str_replace(".html", "", $this->reg_real_id($v["url"])[0]);     }     M()->startTrans();     foreach ($data as $k1 => $v1) {         $res["area_id"] = $v1["url"];         $res["area_pid"] = $toplevel["area_id"];         $res["level"] = 2;         $res["area_name"] = $v1["name"];         if (!$this->areamodel->data($res)->add()) {             echo "循环导入失败" . M()->getLastSql();             die;             M()->rollback();         }     }     $this->areamodel->where(array("area_id" => $fatherid))->save(array("imported" => 1));     $sql = M()->getLastSql();     M()->commit();     echo "导入成功 " . $sql; … Read more

拼多多之多多客SDK

前天开始撸的多多客的SDK  拼多多开放平台官方地址  http://open.pinduoduo.com/#/index 多多进宝官方地址  http://jinbao.pinduoduo.com/#/ 开源地址  https://github.com/adamin1990/Duoduoke 使用方法: require_once("Duoduoke.php"); $config['client_id']="your client id"; $config['client_secret']="your client secret"; $config['duoduoke_redirect_url']="";  //可选 $config["access_token"]="";  //可选 $ddk=new Duoduoke($config); echo $ddk->api_goods_cat_get();