php 小记

1.数据库地址错误也会报这个错,不一定是pdo扩展没装。

PDOException in Connection.php line 293

2.halt($xx) 结束输出结果

  fetchSql(); 输出sql语句

3.echo phpinfo();      输出php配置信息

4.

php的闭包(Closure)也就是匿名函数。是PHP5.3引入的。 

闭包的语法很简单,需要注意的关键字就只有use,use意思是连接闭包和外界变量。 

php闭包函数用use传参有什么意义?答:use引用外层变量,比如全局变量

为什么要使用闭包:

1.减少foreach的循环的代码

2.减少函数的参数

3.解除递归函数

4.关于延迟绑定

使用示例:


<?php
$name = 'xiaochuan';
$test = function ($name='test',$age=10) use ($name) {
//这里的name 不是用的传递的名字 而是 use 中
echo $name;
echo '<br>';
echo $age;
//花括号后面的 分号一定要加不然会报错
};
$test('xiaodou',20);

?>

$map = [
            'index' => [
                'text' => '首页',
            ],
            'cart' => [
                'text' => '购物车',
            ],
            'mine' => [
                'text' => '我的',
            ],
            'collection' => [
                "text" => "收藏"
            ],
            'bestforyou' => [
                "text" => "优选"
            ]
        ];
        $theme = 1;
        $plugin = 0;

        $tab = ['index'];
        if ($theme== 1) {
            $tab[] = 'collection';
            $tab[] = 'bestforyou';
        }

        if ($plugin) {
            $tab[] = 'cart';
        }

        $tab[] = 'mine';
        var_dump($tab);
        $tabIndex = array_flip($tab);    // 反转数组中的键名和对应关联的键值
var_dump($tabIndex);
        $tablist = array_map(function ($v) use ($map) {
            return $map[$v];
        }, $tab);
        //if ($theme == 1) {
          //  $tablist[0]['selectedIconPath'] = '/assets/images/theme1_home_actived.png';
        //}
        var_dump($tablist);
        var_dump($tabIndex);

有道词典
if ($theme == 1 ...
详细X
  如果(主题= = 1美元){   美元tablist [0] [' selectedIconPath ') = ' /资产/图片/ theme1_home_actived.png ';   }

原文地址:https://www.cnblogs.com/ygyy/p/12552935.html