<?php
/**
 * Link         :   http://www.phpcorner.net
 * User         :   qingbing<780042175@qq.com>
 * Date         :   2018-10-27
 * Version      :   1.0
 */

namespace Test;

use TestCore\Tester;

class TestFunction extends Tester
{
    /**
     * 执行函数
     * @throws \Exception
     */
    public function run()
    {
        // 数组覆盖
        $a = [
            "name" => "qingbing",
            "qq" => "10000",
            "mail" => "10000@qq.com",
        ];
        $ab = [
            "xx" => "xx",
            "name" => "xx",
        ];
        $cc = array_cover($a, $ab);
        var_dump($cc);
        $cc = array_cover($a, $ab, false);
        var_dump($cc);
        // 字符串关键字替换
        $str = "Hello, {yourName}. I am {myName}";
        var_dump($str);
        $RStr = str_cover($str, [
            "{yourName}" => 'Balala',
            "{myName}" => 'Qingbing',
        ]);
        var_dump($RStr);
        // 执行字符串类型的代码并返回
        $result = str_eval("5+3*6");
        var_dump($result);
        $result = str_eval('new \Helper\Coding()');
        var_dump($result);
        // 字符串分割,自带空格去除功能
        $a = str_explode(' username , password , sex');
        var_dump($a);
        $a = str_explode(' username| password | sex', '|');
        var_dump($a);
        $a = str_explode(' username| password | sex');
        var_dump($a);
        // 根据大写字母和指定列表进行字符串分割，并全部转换成小写
        $a = str_explode_by_upper('goodProductInfo', ['nf']);
        var_dump($a);
        $a = str_explode_by_upper('goodProductInfo', ['u', 'c']);
        var_dump($a);

        // 数组排序
        $arr = ['b' => 'b', 'a' => 'a', 'c' => 'c'];
        $arr2 = array_sort($arr);
        var_dump($arr2);
        // 数组递归排序
        $arr = ['b' => 'b', 'a' => [
            'dd' => 'dd',
            'cc' => 'cc',
            'ee' => 'ee',
        ], 'c' => 'c'];
        $arr2 = array_sort($arr, true);
        var_dump($arr2);

    }
}