我有两个阵列.我想连接到以下格式.格式如下所示.
Getting form values using post method
/************ Getting Form names like Weight,arms Age etc **********************/
foreach ($_POST["form_field_names"] as $key => $values) {
$form_field_name = $values;
}
/************ Getting Form Values like 45,90,2 **********************/
foreach ($_POST["form_field_values"] as $key => $values) {
$form_field_values[] = $values;
}
Array
(
[0] => Age
[1] => Weight
[2] => Arms
)
Array
(
[0] => 45
[1] => 90
[2] => 2
)
Run Code Online (Sandbox Code Playgroud)
想要连接到以下格式
$output = $Age.","."45".",".$Weight.","."90".",".$Arms.","."2".",";
Run Code Online (Sandbox Code Playgroud)
可能吗?谢谢
我建议您首先将两个数组合并为一个关联数组:
$assoc = array_combine($keys_array1, $num_array2);
Run Code Online (Sandbox Code Playgroud)
然后,只需循环生成输出字符串:
$str = "";
foreach ($assoc as $key=>$num) {
$str .= "$key,$num,";
}
Run Code Online (Sandbox Code Playgroud)
如果尾随,是一个问题(你没有说),那么我会采取一种$str = rtrim($str, ",")解决方法.