我已经学会了如何组合2个数组,所以我创建了第一个$ array1,它将是循环字段的名称,第二个$ array2将是字段selft的值,如下所示
$array1 = array ( Field One, Field Two, Field Three );
然后第二个数组派生自mysql表,例如
$array2 = $conn->db_FetchResult("SELECT id FROM %sfields ...);
$ array2 的结果视图,例如
$array2 = array (field_1 => '1', field_2 => '2', field_3 => '3' );
如何组合这两个数组?
预期输出:
$array3 = array (Field One => '1', Field Two => '2', Field Three => '3' );
我试过使用array_combine,array_merge
print_r(array_combine($ array1,$ array2)as $ array => $ value);
但无法完成它, 我没有找到完全相同的例子,可能愿意提供帮助,谢谢
答案 0 :(得分:1)
<?php
$array1 = array ( "Field One", "Field Two", "Field Three" );
$array2 = array ("field_1" => '1', "field_2" => '2', "field_3" => '3' );
$c=array_combine($array1,$array2);
print_r($c);
<强>输出:强>
Array
(
[Field One] => 1
[Field Two] => 2
[Field Three] => 3
)