在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/ PHP問(wèn)答
巷尾 回答

代碼:

$arr = [
    ['value' => '顏色', 'detailValue' => '', 'attrHidden' => true, 'detail' => ['白色','黑色']],
    ['value' => '包裝', 'detailValue' => '', 'attrHidden' => true, 'detail' => ['大','小']],
    ['value' => '規(guī)則', 'detailValue' => '', 'attrHidden' => true, 'detail' => ['1','2']]
];

function decare($arr){
    $data = [];
    $res = [];
    for ($i=0; $i < count($arr)-1; $i++) { 

        if($i == 0){
            $data = $arr[$i]['detail'];
        }
        //替代變量1
        $rep1 = [];

        foreach ($data as $v) {
            foreach ($arr[$i+1]['detail'] as $g) {
                //替代變量2
                $rep2 = ($i!=0?'':$arr[$i]['value']."_").$v."-".$arr[$i+1]['value']."_".$g;
                $tmp[] = $rep2;
                if($i==count($arr)-2){
                    foreach (explode('-', $rep2) as $k => $h) {
                        //替代變量3
                        $rep3 = explode('_', $h);
                        //替代變量4
                        $rep4['detail'][$rep3[0]] = $rep3[1];
                    }
                    $res[] = $rep4;
                }
            }
        }

        $data = $tmp;
    }
    return [$data,$res];
}
print_r(decare($arr)[1]);

結(jié)果:

clipboard.png

忠妾 回答

arrayFn方法里面的bb不是數(shù)組,不能遞歸了

    function arrayFn(data) {
        data.forEach(item => {
            if (item.age < 30 && item.age>10 ) {
                console.log(item)
            }
            item.children.forEach(bb => {
                arrayFn(bb) // 這個(gè)bb不是數(shù)組
            })

        })
    }

你要判斷是否有children, 然后遞歸

    function arrayFn(data) {
        data.forEach(item => {
            if (item.age < 30 && item.age>10 ) {
                console.log(item)
            }
            if(item.children) {
                arrayFn(item.children)
            }
        })
    }

結(jié)果
clipboard.png

去掉children

    function arrayFn(data) {
        data.forEach(item => {
            if(item.children) {
                arrayFn(item.children)
            }
            if (item.age < 30 && item.age>10 ) {
                delete item.children
                console.log(item)
            }
            
        })
    }

結(jié)果

clipboard.png

厭惡我 回答

env('DB_USERNAME', 'forge') 代碼是在 .env 文件里沒(méi)有配置 DB_USERNAME 時(shí)才采用第二個(gè)參數(shù)的值。

你已經(jīng)通過(guò) .env 文件里的數(shù)據(jù)配置項(xiàng)去配置數(shù)據(jù)庫(kù)信息,所以再 database.php 去修改配置是沒(méi)有作用的。

根據(jù)錯(cuò)誤提示:你是使用 root 賬號(hào)去訪問(wèn) localhost 的本地 mysql,但是你的 .env 和 database.php 文件中都是配置的一個(gè)具體 IP 地址。

所以肯定不是去讀取的這兩個(gè)文件,所以需要確定:

  1. 配置是否有緩存。
  2. 是否有其他配置覆蓋了你的配置。
菊外人 回答

connect,用戶連接上之后就去數(shù)據(jù)庫(kù)查詢好友相關(guān)的信息返回給用戶

傻丟丟 回答

怎么說(shuō)呢 現(xiàn)在比較常用的還是通過(guò).env文件設(shè)置本地環(huán)境的相關(guān)配置吧

不將.env文件加入版本控制, 導(dǎo)出的時(shí)候就不存在.env文件就不用擔(dān)心替換的事情.

我甘愿 回答

原來(lái)在thinkphp5下的Model.php實(shí)現(xiàn)了JSON 序列化接口, 調(diào)用了Model.php的toArray方法,所以json_encode才會(huì)輸出這樣的數(shù)據(jù)出來(lái).

實(shí)現(xiàn) JsonSerializable 的類可以在 json_encode() 時(shí)定制他們的 JSON 表示
// JsonSerializable
public function jsonSerialize()
{
    return $this->toArray();
}

參考資料:
JSON 序列化接口

熟稔 回答
  1. 新開(kāi)一個(gè)隱藏窗口
  2. 在隱身窗口 訪問(wèn) cars.com 》》外國(guó)網(wǎng)站
  3. 修改host文件
  4. 在正常窗口(此前沒(méi)有訪問(wèn)過(guò)cars.com這個(gè)站點(diǎn)) 》》本地站點(diǎn)
  5. 關(guān)閉隱身窗口,再打開(kāi)一個(gè)隱身窗口 訪問(wèn) cars.com 》》外國(guó)站點(diǎn)
  6. 清除緩存后,隱身模式窗口訪問(wèn) cars.com 》》外國(guó)站點(diǎn)

由此可以猜測(cè)應(yīng)該是瀏覽器的某個(gè)機(jī)制的問(wèn)題導(dǎo)致了這個(gè)問(wèn)題

解決方法:可以試一下完全退出瀏覽器程序后再重新打開(kāi)訪問(wèn)

陪她鬧 回答

otter可指定db,table,column同步數(shù)據(jù)

這里的指定可以指定A庫(kù)的B表的C字段同步到D庫(kù)的E表的F字段,字段類型一致即可

select 用戶id,sum(gprice) from (
select 用戶id,項(xiàng)目,sum(A.price*B.比例) as gprice from A join b on a.項(xiàng)目 = b.項(xiàng)目 group by 用戶id,項(xiàng)目 ) group 用戶id

離殤 回答

$數(shù)組3 = array_merge($數(shù)組1, $數(shù)組2);

遲月 回答

最后用的是sqlsrv自帶的HASHBYTES('SHA1',$str) ,然后插入。

小眼睛 回答

需要保證所有的數(shù)據(jù)都同時(shí)操作成功,或者同時(shí)操作失敗。 是指如果a10操作失敗了,全部數(shù)據(jù)回滾到a1操作前嗎?如果是這樣的話,當(dāng)然是吧事務(wù)放在循環(huán)外層最合適。

如果只是 “a1插入后得到的主鍵ID更新到b1的一個(gè)字段” 是一個(gè)事務(wù),其中任意一組操作失敗不影響其他組操作的話,還是應(yīng)該將事務(wù)放在循環(huán)內(nèi)。

// 用于記錄失敗的操作的key
$error = [];

foreach($arr_a AS $key => $a){
    $transaction = Yii::$app->getDb()->beginTransaction();

    try {
        //插入 a1 得到 id1
        //將ID更新到 b1
        
        $transaction->commit();
    } catch (\Exception $e) {

        // 回滾
        $transaction->rollBack();
        // 記錄失敗的操作的key
        $error[] = $key;

        // 這里不拋異常
        continue;
    }
}

// 對(duì)記錄的 $error 進(jìn)行其他操作
執(zhí)念 回答

首先,你的 $config 數(shù)組中一定包含以下元素:

$config = [
    //others
    'modules' => [
        'debug' => [
            'class' => 'yii\debug\Module',
        ], 
        'gii'   => [
            'class' => 'yii\gii\Module',
        ];
    ],
    //others
]

這里說(shuō)明一下繼承關(guān)系:

class yii\base\Application extends yii\base\Module

class yii\base\Module extends yii\di\ServiceLocator

class yii\di\ServiceLocator extends yii\base\Component

class yii\base\Component extends yii\base\Object

  • yiibaseApplication::__construct() 方法注解
public function __construct($config = [])
{
    Yii::$app = $this;
    //將\yii\base\Application中的所有的屬性和方法交給Yii::$app->loadedModules數(shù)組中
    static::setInstance($this);

    $this->state = self::STATE_BEGIN;

    //加載配置文件的框架信息 如:設(shè)置別名,設(shè)置框架路徑等等最為重要的是給加載默認(rèn)組件
    $this->preInit($config);

    //加載配置文件中的異常組件
    $this->registerErrorHandler($config);

    // 調(diào)用父類的 __construct。
    // 由于Component類并沒(méi)有__construct函數(shù)
    // 這里實(shí)際調(diào)用的是 `yii\base\Object__construct($config)`
    Component::__construct($config);
}

上面方法中 Component::__construct($config) 會(huì)調(diào)用 yii\base\Object::__construct() 方法

  • yiibaseObject::__construct() 方法注解
public function __construct($config = [])
{
    if (!empty($config)) {
        // 將配置文件里面的所有配置信息賦值給Object。
        // 由于Object是大部分類的基類,
        // 實(shí)際上也就是有配置信息賦值給了yii\web\Application的對(duì)象
        Yii::configure($this, $config);
    }
    $this->init();
}

一、下面只是為了說(shuō)明 'components' => [ 'log' => [...]] 從哪來(lái),若不關(guān)心可以直接看 第二步。

  • 先看 $this->preInit($config);,即 yii\base\Application::preInit(&$config)
public function preInit(&$config)
{
    //others...
    
    // merge core components with custom components
    // 合并核心組件和自定義組件
    foreach ($this->coreComponents() as $id => $component) {
        if (!isset($config['components'][$id])) {
            // 若自定義組件中沒(méi)有設(shè)置該核心組件配置信息,直接使用核心組件默認(rèn)配置
            $config['components'][$id] = $component;
        } elseif (is_array($config['components'][$id]) && !isset($config['components'][$id]['class'])) {
            // 若自定義組件有設(shè)置該核心組件配置信息,但是沒(méi)有設(shè)置 'class'屬性,則添加該class屬性
            $config['components'][$id]['class'] = $component['class'];
        }
    }
}

/**
 * Returns the configuration of core application components.
 * 返回核心應(yīng)用組件的配置
 * @see set()
 */
public function coreComponents()
{
    return [
        // 日志分配器組件
        'log' => ['class' => 'yii\log\Dispatcher'],
        
        //others...
    ];
}
  • 經(jīng)過(guò) $this->preInit($config);, 我們得到的 $config
$config = [
    'modules' => [
        'debug' => [
            'class' => 'yii\debug\Module',
        ], 
        'gii'   => [
            'class' => 'yii\gii\Module',
        ];
    ],
    'components' => [
        'log'   => [
            'class' => 'yii\\log\\Dispatcher',
        ],
        
        //others...
    ]
    //others...
]


上面只是為了說(shuō)明 'components' => [ 'log' => [...]] 從哪來(lái)

二、重點(diǎn)在這里

  • yii\base\Object::__construct($config = []) 中的 Yii::configure($this, $config);
public static function configure($object, $properties)
{
    // 只是遍歷配置信息,賦值給當(dāng)前對(duì)象
    foreach ($properties as $name => $value) {
        $object->$name = $value;
    }
    return $object;
}
  • 這里我們要配合 yii\base\Object::__set($name, $value)
/**
 * 為實(shí)例不存在的屬性賦值時(shí)調(diào)用
 *
 * Do not call this method directly as it is a PHP magic method that
 * will be implicitly called when executing `$object->property = $value;`.
 * 這個(gè)是PHP的魔術(shù)方法,會(huì)在執(zhí)行 `$object->property = $value;` 的時(shí)候自動(dòng)調(diào)用。
 */
public function __set($name, $value)
{
    // setter函數(shù)的函數(shù)名
    // 由于php中方法名稱不區(qū)分大小寫(xiě),所以setproperty() 等價(jià)于 setProperty()
    $setter = 'set' . $name;
    if (method_exists($this, $setter)) {
        // 調(diào)用setter函數(shù)
        $this->$setter($value);
    } elseif (method_exists($this, 'get' . $name)) {
        // 如果只有g(shù)etter沒(méi)有setter 則為只讀屬性
        throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);
    } else {
        throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
    }
}

當(dāng)前情景下的 $object 我們可以認(rèn)為是 yii\base\Application 的對(duì)象 $app

  • 當(dāng)遍歷到:
$app->modules =  [
    'debug' => [
        'class' => 'yii\debug\Module',
    ], 
    'gii'   => [
        'class' => 'yii\gii\Module',
    ];
]

這里會(huì)調(diào)用 yii\base\Module::setModules($modules) 方法

public function setModules($modules)
{
    foreach ($modules as $id => $module) {
        $this->_modules[$id] = $module;
    }
}

這樣便有了問(wèn)題中的

["_modules":"yii\base\Module":private]=>
    array(3) {
        ["debug"]=> object(yii\debug\Module)#33 (28) {
            ......
        }
        ["gii"]=> object(yii\gii\Module)#113 (21) {
            ......
        }
        ...
    }
  • 同樣的道理,當(dāng)遍歷到:
$app->components =  [
    'log'   => [
        'class' => 'yii\\log\\Dispatcher',
    ],
]
  • 這里會(huì)調(diào)用 yii\di\ServiceLocator::setComponents($components) 方法
public function setComponents($components)
{
    foreach ($components as $id => $component) {
        $this->set($id, $component);
    }
}

public function set($id, $definition)
{
    // others ...

    if (is_object($definition) || is_callable($definition, true)) {
        // an object, a class name, or a PHP callable
        $this->_definitions[$id] = $definition;
    } elseif (is_array($definition)) {
        // 定義如果是個(gè)數(shù)組,要確保數(shù)組中具有 class 元素
        // a configuration array
        if (isset($definition['class'])) {
            // 定義的過(guò)程,只是寫(xiě)入了 $_definitions 數(shù)組
            $this->_definitions[$id] = $definition;
        } else {
            throw new InvalidConfigException("The configuration for the \"$id\" component must contain a \"class\" element.");
        }
    } else {
        throw new InvalidConfigException("Unexpected configuration type for the \"$id\" component: " . gettype($definition));
    }
}

這樣便有了問(wèn)題中的

["_definitions":"yii\di\ServiceLocator":private]=>
        array(24) {
            ["errorHandler"]=> .....
            ["request"]=> ......
            ["log"]=> ......
            ......
        }
局外人 回答

mysql查詢是在磁盤(pán)上面進(jìn)行IO操作,php循環(huán)是在內(nèi)存中進(jìn)行,你的第一個(gè)方法的循環(huán)查詢會(huì)慢一些。 如果數(shù)據(jù)庫(kù)中數(shù)據(jù)量過(guò)大,內(nèi)存占用過(guò)大,建議分片讀取處理

尐潴豬 回答

你的想法以前也有人想過(guò)的, 然后 pjax 就出來(lái)了

小曖昧 回答

關(guān)于訪問(wèn)url的方式可以改下。ThinkPHP可以自定義命令行自定義命令行
把“循環(huán)數(shù)據(jù),狀態(tài)有變化的就推送微信消息給用戶”這個(gè)邏輯寫(xiě)入命令行中,不需要通過(guò)訪問(wèn)url的形式觸發(fā),也能避免安全問(wèn)題,nginx的資源問(wèn)題等。

1 * * * * * /usr/bin/php think test