以下是代码
print_r($_POST).'<br><br>';
foreach($_POST as $key => $value){
if(is_array($value))
{
foreach($value as $key => $value)
{
echo "<br><br>".$key." ".$value."<br>";
}
}
echo "<br>";
}
输出是
数组([Cake_on_Name] =>数组([0] => Rachana [1] => Sarika [2] => Pratik)[Cake_on_Date] =>数组([0] => 2017-12-19 [1] => 2017-12-19 [2] => 2017-12-19)[Cake_on_Time] =>数组([0] => 10 AM [1] => 10 AM [2] => 10 AM)[Cake_Receiver_Name] =>数组([0] => [1] => [2] => Ashvin Ade)[Cake_on_Address] =>数组([0] => [1] => [2] => Amravati)[pincode] =>数组([0] => 444607 [1] => 444607 [2] => 444607)[cheu] => 1-1 @ 500,54-1 @ 1000,65-1 @ 1000,54-1 @ 300,56 -1 @ 1000,65-1 @ 300,54-1 @ 1000 [clientinput] =>添加细节和购买)
0组成
1排
2实用
0 2017-12-19
1 2017-12-19
2 2017-12-19
0 10 A.M.
1 10 A.M.
2 10 A.M.
0
1
2 Ashwin Adar
0
1
2 Amravati
0 444607
1 444607
2 444607
但我希望输出为:
0组成
0 2017-12-19
0 10 A.M.
0
0
0 444607
1排
1 2017-12-19
1 10 A.M.
1
1
1 444607
2实用
2 2017-12-19
2 10 A.M.
2 Ashwin Adar
2 Amravati
2 444607
你可以试试这个。
$length = count($_POST["Cake_on_Name"]);
for($i=0; $i<=$length;$i++) {
foreach($_POST as $key => $value)
{
echo $i ." ". $value[$i]."<br>";
}
}
你可以使用array_map
并迭代结果。
$zipped = array_map(null, ...array_values($_POST));
foreach ($zipped as $item) {
foreach ($item as $index => $value) {
echo $index . ' ' . $value;
}
}