0 follower

Class yii\helpers\ReplaceArrayValue

繼承yii\helpers\ReplaceArrayValue
自版本起可用2.0.10
原始碼 https://github.com/yiisoft/yii2/blob/master/framework/helpers/ReplaceArrayValue.php

代表執行 yii\helpers\ArrayHelper::merge() 時陣列值替換的物件。

使用範例

$array1 = [
    'ids' => [
        1,
    ],
    'validDomains' => [
        'example.com',
        'www.example.com',
    ],
];

$array2 = [
    'ids' => [
        2,
    ],
    'validDomains' => new \yii\helpers\ReplaceArrayValue([
        'yiiframework.com',
        'www.yiiframework.com',
    ]),
];

$result = \yii\helpers\ArrayHelper::merge($array1, $array2);

結果將會是

[
    'ids' => [
        1,
        2,
    ],
    'validDomains' => [
        'yiiframework.com',
        'www.yiiframework.com',
    ],
]

公開屬性

隱藏繼承的屬性

屬性 類型 描述 定義於
$value 混合 用作替換的值。 yii\helpers\ReplaceArrayValue

公開方法

隱藏繼承的方法

方法 描述 定義於
__construct() 建構子。 yii\helpers\ReplaceArrayValue
__set_state() 在使用 var_export() 後還原類別狀態。 yii\helpers\ReplaceArrayValue

屬性詳細資訊

隱藏繼承的屬性

$value 公開屬性

用作替換的值。

public mixed $value null

方法詳細資訊

隱藏繼承的方法

__construct() 公開方法

建構子。

public void __construct ( $value )
$value 混合

用作替換的值。

                public function __construct($value)
{
    $this->value = $value;
}

            
__set_state() 公開靜態方法 (自版本 2.0.16 起可用)

在使用 var_export() 後還原類別狀態。

另請參閱 https://php.dev.org.tw/manual/en/function.var-export.php

public static yii\helpers\ReplaceArrayValue __set_state ( $state )
$state 陣列
拋出 yii\base\InvalidConfigException

當 $state 屬性不包含 value 參數時

                public static function __set_state($state)
{
    if (!isset($state['value'])) {
        throw new InvalidConfigException('Failed to instantiate class "ReplaceArrayValue". Required parameter "value" is missing');
    }
    return new self($state['value']);
}