我有两个数组:
Array 1
(
[0] => Daughter
[1] => Daughter
[2] => Son
)
Array 2
(
[0] => Nitu
[1] => ritu
[2] => ramesh
)
我希望每个键都有不同的数组,如下所示:
Array(
"relation" => Daughter
"name" => Nitu
)
Array(
"relation" => Daughter
"name" => ritu
)
Array(
"relation" => Son
"name" => ramesh
)
以上数组1&根据用户输入,数组2可以很长。所以我想动态地在循环中向新数组插入值。
答案 0 :(得分:0)
试试这个,
$Aarray1 = Array
(
"0" => "Daughter",
"1" => "Daughter",
"2" => "Son"
);
$Aarray2 = Array
(
"0" => "Nitu",
"1" => "ritu",
"2" => "ramesh"
);
foreach($Aarray1 as $key=>$val)
{
$new_array[$key]["relation"] = $val;
$new_array[$key]["name"] = $Aarray2[$key];
}
<强> DEMO 强>
答案 1 :(得分:0)
您只需循环遍历数组并将其存储在变量public static DataView ElecDv480V(System.Data.DataTable dt)
{
System.Data.DataView dv = new DataView(dt);
dv.RowFilter = "F1 = '480V'";
dv.Sort = "F2 ASC, F3 ASC";
System.Data.DataTable dt480 = dv.ToTable();
return dv;
}
中。
试试这个:
$result
答案 2 :(得分:0)
试试这个:
$arrayFirst = Array("0" => "Daughter", "1" => "Daughter", "2" => "Son");
$arraySecond = Array("0" => "Nitu","1" => "ritu","2" => "ramesh");
foreach($arrayFirst as $key=>$value)
{
$new_array[$key]["relation"] = $value;
$new_array[$key]["name"] = $arraySecond[$key];
}
答案 3 :(得分:-1)
您可能正在尝试搜索 array_combine
您可以查看文档here