3个阵列的动态数组

时间:2013-11-30 20:37:51

标签: php arrays

我有2个常量元素的数组

$this->Properties = array(
"ConstName1"   => $ConstVal_1, "ConstName2"   => $ConstVal_2
);

如何从另一个数组

添加到此数组动态元素(名称元素)
$this->Names = array(
"DynName1"   => $Name_1, "DynName2"   => $Name_2
);

并将3个数组中的元素值放入

$this->Values = array(
"DynVal1"   => $Val_1, "DynVal2"   => $Val_2
);

最终:我尝试将第二个数组中的$ Name_1 /作为名称/和第三个数组中的$ Val_1 /作为值/,然后将/ $ Name_1 => $ Val_1 /并添加到第一个数组

提前致谢!

1 个答案:

答案 0 :(得分:0)

$this->Properties = array_merge(
    array("ConstName1"   => $ConstVal_1, "ConstName2"   => $ConstVal_2),
    array("DynName1"   => $Name_1, "DynName2"   => $Name_2),
    array("DynVal1"   => $Val_1, "DynVal2"   => $Val_2)
);

或者:

$this->Properties = array();

$this->Properties = array_merge(
    $this->Properties,
    array("ConstName1"   => $ConstVal_1, "ConstName2"   => $ConstVal_2)
);

$this->Properties = array_merge(
    $this->Properties,
    array("DynName1"   => $Name_1, "DynName2"   => $Name_2)
);

$this->Properties = array_merge(
    $this->Properties,
    array("DynVal1"   => $Val_1, "DynVal2"   => $Val_2)
);

甚至:

$this->Properties = array();

$this->Properties["DynVal1"] = $Val_1;
$this->Properties["DynVal2"] = $Val_2;
// and so on