专业技能回归基础强化。

专业技能回归基础强化。

一、每周测试并记录不常用的   php 或 javascript 函数10个。

2020年12月04日 - 周

  1. array_flip($arr);  //交换数组中的键和值 https://www.runoob.com/php/func-array-flip.html

  2. method_exists(object,method_name); //检查类的方法是否存在 https://www.php.net/manual/zh/function.method-exists.php

  3. array_filter($array) ; // 过滤数组中的元素    https://www.runoob.com/php/func-array-filter.html

  4. filter_has_var() ; // 检查是否存在指定输入类型的变量。https://www.w3school.com.cn/php/func_filter_has_var.asp

  5. filter_id(); //返回指定过滤器的 ID 号。https://www.w3school.com.cn/php/func_filter_id.asp

  6. filter_input(); // 从脚本外部获取输入,并进行过滤。https://www.w3school.com.cn/php/func_filter_input.asp

  7. filter_input_array(); //从脚本外部获取多项输入,并进行过滤。https://www.w3school.com.cn/php/func_filter_input_array.asp

  8. filter_list(); //返回包含所有得到支持的过滤器的一个数组。https://www.w3school.com.cn/php/func_filter_list.asp

  9. filter_var_array(); //获取多项变量,并进行过滤。https://www.w3school.com.cn/php/func_filter_var_array.asp

  10. filter_var(); //获取一个变量,并进行过滤。https://www.w3school.com.cn/php/func_filter_var.asp

  11. extract(); //一个数组分解成多个变量 https://www.cnblogs.com/xingyazhao/p/7152111.html

https://www.runoob.com/php/func-array-extract.html

2020年12月11日 - 周

  1. array_column() //返回输入数组中某个单一列的值。https://www.w3school.com.cn/php/func_array_column.asp

  2. array_merge() //把一个或多个数组合并为一个数组 https://www.runoob.com/php/func-array-merge.html

  3. array_unshift() //数组的开头插入新元素 https://www.runoob.com/php/func-array-unshift.html

  4. array_keys() //数组key重新排列 https://www.runoob.com/php/func-array-keys.html

  5. array_slice(array,start,length,preserve) //在数组中根据条件取出一段值,并返回  https://www.w3school.com.cn/php/func_array_slice.asp

  6. array_key_exists(key,array) //检查数组键名是否存在 https://www.w3school.com.cn/php/func_array_key_exists.asp

  7. array_unique() //移除数组中重复的值 https://www.runoob.com/php/func-array-unique.html

  8. array_pop(array) //删除数组中的最后一个元素。 https://www.w3school.com.cn/php/func_array_pop.asp

  9. array_search() //在数组中搜索某个键值,并返回对应的键名  https://www.runoob.com/php/func-array-search.html

  10. array_chunk(array,size,preserve_key); //把数组分割为新的数组块 https://www.w3school.com.cn/php/func_array_chunk.asp

2020年12月18日 - 周

  1. set_time_limit ($seconds)   //设置脚本最大执行时间    https://www.php.net/manual/zh/function.set-time-limit.php

  2. strip_tags("Hello <b>world!</b>");   //剥去字符串中的 HTML 标签: https://www.w3school.com.cn/php/func_string_strip_tags.asp

  3. iconv("UTF-8","GB2312//IGNORE",$data)   //字符集间的转换   https://www.jb51.net/article/14530.htm

  4. is_dir(file)   //检查指定的文件是否是目录。 https://www.w3school.com.cn/php/func_filesystem_is_dir.asp

  5. mkdir(path,mode,recursive,context)   //创建文件夹   https://www.runoob.com/php/func-filesystem-mkdir.html

  6. stripos() // 查找字符串在另一字符串中第一次出现的位置(不区分大小写) https://www.w3school.com.cn/php/func_string_stripos.asp

  7. strpos() // 查找字符串在另一字符串中第一次出现的位置(区分大小写) https://www.w3school.com.cn/php/func_string_strpos.asp

  8. strripos() // 查找字符串在另一字符串中最后一次出现的位置(不区分大小写) https://www.w3school.com.cn/php/func_string_strripos.asp

  9. end() //得到数组中最后一个元素值;https://www.runoob.com/php/func-array-end.html

  10. file_put_contents() //函数把一个字符串写入文件中。 https://www.runoob.com/php/func-filesystem-file-put-contents.html


2020年12月25日 - 周

  1. file_get_contents() //函数把整个文件读入一个字符串中。//https://www.runoob.com/php/func-filesystem-file-get-contents.html

  2. preg_match() // 执行匹配正则表达式  https://www.php.net/manual/zh/function.preg-match.php

  3. preg_match_all() //与preg_match()不同于此,它会一直搜索subject 直到到达结尾。 如果发生错误preg_match()返回 FALSE。https://www.runoob.com/php/php-preg_match_all.html

  4. move_uploaded_file(file,newloc) //函数将上传的文件移动到新位置。(常用于文件上传中) https://www.w3school.com.cn/php/func_filesystem_move_uploaded_file.asp

  5. list() //把数组中的值赋给一些变量 例子:list($a,$b)=$my_array; https://www.w3school.com.cn/php/func_array_list.asp

  6. feof() //函数检测是否已到达文件末尾 (eof)。https://www.w3school.com.cn/php/func_filesystem_feof.asp

  7. ini_set()  //为一个配置选项设置值 https://www.php.net/manual/zh/function.ini-set.php

  8. each() // 返回数组中当前的键/值对并将数组指针向前移动一步  https://www.php.net/manual/zh/function.each.php

  9. sys_getloadavg()  //获得系 统负载情况 https://www.php.net/manual/zh/function.sys-getloadavg.php

  10. pack() //函数把数据装入一个二进制字符串。能将md5()返回的32位16进制字符串转换为16位的二进制字符串,可以节省存储空间。https://www.runoob.com/php/func-misc-pack.html


2021年01月01日 - 周

  1. strlen() //返回字符串的长度(字节数) https://www.runoob.com/php/php-string.html

  2. array_change_key_case()//返回其键均为大写或小写的数组。https://www.runoob.com/php/func-array-change-key-case.html

  3. array_combine()//通过合并两个数组(一个为键名数组,一个为键值数组)来创建一个新数组。https://www.runoob.com/php/func-array-combine.html

  4. array_count_values()//用于统计数组中所有值出现的次数。https://www.runoob.com/php/func-array-count-values.html

  5. array_diff()//比较数组,返回两个数组的差集(只比较键值)。https://www.runoob.com/php/func-array-diff.html

  6. array_diff_assoc()//比较数组,返回两个数组的差集(比较键名和键值)。https://www.runoob.com/php/func-array-diff-assoc.html

  7. array_diff_key()//比较数组,返回两个数组的差集(只比较键名)。https://www.runoob.com/php/func-array-diff-key.html

  8. array_diff_uassoc()//比较数组,返回两个数组的差集(比较键名和键值,使用用户自定义的键名比较函数)。https://www.runoob.com/php/func-array-diff-uassoc.html

  9. array_diff_ukey()//比较数组,返回两个数组的差集(只比较键名,使用用户自定义的键名比较函数)。https://www.runoob.com/php/func-array-diff-ukey.html

  10. array_fill()//用给定的键值填充数组。https://www.runoob.com/php/func-array-fill.html

2021年01月08日 - 周

  1. array_fill_keys()//用给定的指定键名的键值填充数组。https://www.runoob.com/php/func-array-fill-keys.html

  2. array_flip()反转/交换数组中的键名和对应关联的键值。https://www.runoob.com/php/func-array-flip.html

  3. array_intersect()比较数组,返回两个数组的交集(只比较键值)。https://www.runoob.com/php/func-array-intersect.html

  4. array_intersect_assoc()比较数组,返回两个数组的交集(比较键名和键值)。https://www.runoob.com/php/func-array-intersect-assoc.html

  5. array_intersect_key()比较数组,返回两个数组的交集(只比较键名)。https://www.runoob.com/php/func-array-intersect-key.html

  6. array_intersect_uassoc()比较数组,返回两个数组的交集(比较键名和键值,使用用户自定义的键名比较函数)。https://www.runoob.com/php/func-array-intersect-uassoc.html

  7. array_intersect_ukey()比较数组,返回两个数组的交集(只比较键名,使用用户自定义的键名比较函数)。https://www.runoob.com/php/func-array-intersect-ukey.html

  8. array_map()将用户自定义函数作用到给定数组的每个值上,返回新的值。https://www.runoob.com/php/func-array-map.html

  9. array_merge_recursive()递归地把一个或多个数组合并为一个数组。https://www.runoob.com/php/func-array-merge-recursive.html

  10. array_multisort()对多个数组或多维数组进行排序。https://www.runoob.com/php/func-array-multisort.html

2021年01月15日 - 周

  1. array_pad()将指定数量的带有指定值的元素插入到数组中。https://www.runoob.com/php/func-array-pad.html

  2. array_product()计算数组中所有值的乘积。https://www.runoob.com/php/func-array-product.html

  3. array_push()将一个或多个元素插入数组的末尾(入栈)。https://www.runoob.com/php/func-array-push.html

  4. array_rand()从数组中随机选出一个或多个元素,返回键名。https://www.runoob.com/php/func-array-rand.html

  5. array_reduce()通过使用用户自定义函数,迭代地将数组简化为一个字符串,并返回。https://www.runoob.com/php/func-array-reduce.html

  6. array_replace_recursive()递归地使用后面数组的值替换第一个数组的值。https://www.runoob.com/php/func-array-replace-recursive.html

  7. array_shift()删除数组中的第一个元素,并返回被删除元素的值。https://www.runoob.com/php/func-array-shift.html

  8. array_slice()返回数组中的选定部分。https://www.runoob.com/php/func-array-slice.html

  9. array_sum()返回数组中所有值的和。https://www.runoob.com/php/func-array-sum.html

  10. prev()将数组的内部指针倒回一位。https://www.runoob.com/php/func-array-prev.html

2021年01月22日 - 周

  1.  array_udiff()比较数组,返回两个数组的差集(只比较键值,使用一个用户自定义的键名比较函数)。https://www.runoob.com/php/func-array-sum.html

  2. array_udiff_assoc()比较数组,返回两个数组的差集(比较键名和键值,使用内建函数比较键名,使用用户自定义函数比较键值)。https://www.runoob.com/php/func-array-udiff-assoc.html

  3. array_udiff_uassoc()比较数组,返回两个数组的差集(比较键名和键值,使用两个用户自定义的键名比较函数)。

  4. array_uintersect()比较数组,返回两个数组的交集(只比较键值,使用一个用户自定义的键名比较函数)。https://www.runoob.com/php/func-array-uintersect.html

  5. array_uintersect_assoc()比较数组,返回两个数组的交集(比较键名和键值,使用内建函数比较键名,使用用户自定义函数比较键值)。https://www.runoob.com/php/func-array-uintersect-assoc.html

  6. array_uintersect_uassoc()比较数组,返回两个数组的交集(比较键名和键值,使用两个用户自定义的键名比较函数)。https://www.runoob.com/php/func-array-uintersect-uassoc.html

  7. arsort()对关联数组按照键值进行降序排序。https://www.runoob.com/php/func-array-arsort.html

  8. asort()对关联数组按照键值进行升序排序。https://www.runoob.com/php/func-array-asort.html

  9. compact()创建一个包含变量名和它们的值的数组。https://www.runoob.com/php/func-array-compact.html

  10. current()返回数组中的当前元素。https://www.runoob.com/php/func-array-current.html

2021年01月29日 - 周

  1. each()返回数组中当前的键/值对。https://www.runoob.com/php/func-array-each.html

  2. end()将数组的内部指针指向最后一个元素。https://www.runoob.com/php/func-array-end.html

  3. extract()从数组中将变量导入到当前的符号表。https://www.runoob.com/php/func-array-extract.html

  4. key()从关联数组中取得键名。https://www.runoob.com/php/func-array-key.html

  5. krsort()对关联数组按照键名降序排序。https://www.runoob.com/php/func-array-krsort.html

  6. ksort()对关联数组按照键名升序排序。https://www.runoob.com/php/func-array-ksort.html

  7. list()把数组中的值赋给一些数组变量。https://www.runoob.com/php/func-array-list.html

  8. natcasesort()用"自然排序"算法对数组进行不区分大小写字母的排序。https://www.runoob.com/php/func-array-natcasesort.html

  9. natsort()用"自然排序"算法对数组排序。https://www.runoob.com/php/func-array-natsort.html

  10. next()将数组中的内部指针向后移动一位。https://www.runoob.com/php/func-array-next.html

2021年02月05日 - 周

2021年02月12日 - 周


二、学习代码设计模式,每月记录一种设计模式。

2020年12月31日 - 月

简单工厂模式

简单工厂又叫静态工厂方法模式,这样理解可以确定,简单工厂模式是通过一个静态方法创建对象的。

工厂类负责创建的对象较少,客户只知道传入工厂类的参数,对于如何创建对象不关心。

interface  people {
    function  jiehun();
}
class man implements people{
    function jiehun() {
        echo '送玫瑰,送戒指!<br>';
    }
}
  
class women implements people {
    function jiehun() {
        echo '穿婚纱!<br>';
    }
}
  
class SimpleFactoty {
    // 简单工厂里的静态方法
    static function createMan() {
        return new     man;
    }
    static function createWomen() {
        return new     women;
    }
     
}
  
$man = SimpleFactoty::createMan();
$man->jiehun();
$man = SimpleFactoty::createWomen();
$man->jiehun();

2021年01月31日 - 月

策略模式

策略模式就是用来封装算法的,但在实践中,我们发现可以用它来封装几乎任何类型的规则,只要在分析过程中听到需要在不同时间应用不同的业务规则,就可以考虑使用策略模式处理这种变化的可能性。

需求:

超市促销活动,分别有原价,八折,满300减50,使用策略模式……,程序如何设计。

流程图如下:


1. 抽象活动算法类

<?php
/**
 * 抽象活动算法类
 */
namespace strategy;

abstract class StrategyAbstract
{
    /**
     * 具体活动算法方法
     * @return mixed
     */
    public abstract function doAction($money);
}

2. 具体算法产品类

<?php
/**
 * 满减算法产品类
 */
namespace strategy;

class ManJianStrategy extends StrategyAbstract
{
    public function doAction($money)
    {
        echo '满减算法:原价'. $money .'元';
    }
}
<?php
/**
 * 打折算法产品类
 */
namespace strategy;

class DaZheStrategy extends StrategyAbstract
{
    /**
     * 具体算法实现
     * @param $money
     * @return mixed|void
     */
    public function doAction($money)
    {
        echo '打折算法:原价'. $money .'元';
    }
}

3. 策略工厂类

<?php
/**
 * 策略工厂类
 */
namespace strategy;

class StrategyFind
{
    private $strategy_mode;

    /**
     * 初始时,传入具体的策略对象
     * @param $mode
     */
    public function __construct($mode)
    {
        $this->strategy_mode = $mode;
    }

    /**
     * 执行打折算法
     * @param $money
     */
    public function get($money)
    {
        $this->strategy_mode->doAction($money);
    }
}

入口文件

<?php

namespace strategy;

include '../autoload.php';
// 满减折算
$mode1 = new StrategyFind(new ManJianStrategy());
$mode1->get(100);

echo '<br>';

// 满减活动
$mode2= new StrategyFind(new DaZheStrategy());
$mode2->get(100);

策略模式就是使用封装一个公共抽象算法,每个算法(比如,打折算法,满减算法)实现这个接口,然后搞个策略工厂类来调用这些算法。

2021年02月30日 - 月


回复列表


回复操作