将foreach中的数组传递给foreach外的变量?

Im taking data from a form and e-mailing it using wp_mail, since there is multiple data (all check box data) there obviously needs to be a foreach.

I cannot wrap my head around getting the data inside the foreach and using it outside the statement.

 //My form data
 $checks = $_POST['personalization_result'];

 //Pass the foreach array into this variable and use this to mail
 $checkString = '';

    //For each checkbox data
    foreach ($checks as $k => $v) {
     var_dump ($v);
    }

 //Email the data
 $sent = wp_mail($to, $subject, $checkString, $headers); //I have set up the other variables but its not necessary to add here just focused on $checkString

Snippet of the form

<form action="<?php the_permalink(); ?>" method="post"> 

<?php echo $checkString; ?>// Trying to see what the array is doing

<input type="hidden" name="submitted" value="1">

<p><input type="submit"></p>

<li class="option table selected">
    <input type="hidden" value="0" name="personalization_result[memory_0]">
    <input type="checkbox" value="1" name="personalization_result[memory_0]" id="personalization_result_memory_0" checked="checked">                                        
</li> 


<li class="option table selected">
    <input type="hidden" value="0" name="personalization_result[memory_1]">
    <input type="checkbox" value="1" name="personalization_result[memory_1]" id="personalization_result_memory_1" checked="checked">                                    
</li>  

Im sorry if this is a bit noobish, but this is how I learn by asking.

Since wp_mail's third parameter message is a string, I think you can avoid the foreach altogether and use array_values to get values as an array and join them with some glue instead of looping through the $checks array. Please try:

$checkValues = array_values($checks);
$checkString = implode(',', $checkValues); // This generates comma separated list of values.

You could use any glue (comma in this example) you like in the implode function call based on how you want to display the .$checkValues