Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 3个数组中的动态数组_Php_Arrays - Fatal编程技术网

Php 3个数组中的动态数组

Php 3个数组中的动态数组,php,arrays,Php,Arrays,我有一个包含2个常量元素的数组 $this->Properties = array( "ConstName1" => $ConstVal_1, "ConstName2" => $ConstVal_2 ); 如何将另一个数组中的动态元素(命名元素)添加到此数组 $this->Names = array( "DynName1" => $Name_1, "DynName2" => $Name_2 ); 并将3个数组中的值放入该元素 $this-&

我有一个包含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
);
最后:我尝试从第二个数组/as Name/中获取$Name\u 1,从第三个数组/as value/中获取$Val\u 1,然后合并/$Name\u 1=>$Val\u 1/并添加到第一个数组中

提前谢谢

$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["DynVal1"] = $Val_1;
$this->Properties["DynVal2"] = $Val_2;
// and so on

也许您需要
数组\u merge()
?问题有点不清楚。您必须使用array\u combine。听起来可能是您需要使用的
array\u merge()
函数-但从您的问题中,我不确定您要查找的最终输出/数组是什么。。。您是否可以编辑您的问题/评论,并确认所需的最终数组结构/内容?$this->Properties=array(“ConstName1”=>$ConstVal\u 1,“ConstName2”=>$ConstVal\u 2,$Name\u 1=>$Val\u 1,$Name\u 2=>$Val\u 2);谢谢Havenard,但我尝试从第二个数组/as Name/和第三个数组中获取$Name_1/as value/,然后合并/$Name_1=>$Val_1/并添加到第一个数组中……我不确定您的意思。您想给键指定动态名称吗?好像你对某事有错误的概念。
$this->Properties = array();

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