Php 如何将foreach循环值存储到变量中

Php 如何将foreach循环值存储到变量中,php,email,foreach,Php,Email,Foreach,我想在下面的表格中显示这些值 Television Computer Mobile 这样试试 $getallgifts = $_POST['getallgifts[]']; $message = 'Request From : '.$getallgifts.' ------ <form method="post" action="#" class="getfffff" style="text-align:center;"> <?php $fivesdrafts = $wpd

我想在下面的表格中显示这些值

Television
Computer
Mobile
这样试试

$getallgifts = $_POST['getallgifts[]'];
$message = 'Request From : '.$getallgifts.'
------
<form method="post" action="#" class="getfffff" style="text-align:center;">

<?php
$fivesdrafts = $wpdb->get_results( 
    "
    SELECT *
    -----
);

foreach ( $fivesdrafts as $fivesdraft ) 
{
  $user_gift = $fivesdraft->recommend_getdetailgift;
    echo '<input type="hidden" value="' .  $user_gift . '" name="getallgifts[]" >';

}

?>
    <input type="hidden" value="<?php echo $user_sum; ?>" name="getwwitdreawv">
</form>
<?php
$fivesdrafts = $wpdb->get_results(" SELECT  ......   ");
foreach ( $fivesdrafts as $key => $fivesdraft ) {
    $user_gift = $fivesdraft->recommend_getdetailgift;
    echo '<input type="hidden" value="' .  $user_gift . '" name="getallgifts[' . $key . ']" >';
}
?>
更改此部分:

  $getallgifts = $_POST['getallgifts'];
  $message =  'Request From : '

  foreach(  $getallgifts as $gift) {
      $message = $message . $gift;
  }
为此:

$user_gift = $fivesdraft->recommend_getdetailgift;
echo $user_gift;
echo''

这样,您将在
$\u POST
数组中有一个名为
[getallgifts]
的元素,其中将包含一个数组,该
输入的每个实例都将
echo

不起作用。。。上面和下面的答案都不起作用。。输出显示的是数组,但您需要为每一行指定一个不同的getallgifts?我已经更新了答案,为getallgifts数组添加了一个键,以显示所有行。。您编辑的代码甚至没有得到输出..$key=>$fivesdraft编辑..请检查我更新的问题。是的,我也试过了,但也没用。。
  $getallgifts = $_POST['getallgifts'];
  $message =  'Request From : '

  foreach(  $getallgifts as $gift) {
      $message = $message . $gift;
  }
$user_gift = $fivesdraft->recommend_getdetailgift;
echo $user_gift;
echo '<input type="hidden" value="'.$fivesdraft->recommend_getdetailgift.'"
 name="getallgifts[]">'