0

This code displays the contents of an array in the format:

1 2 3 4
1 2 3 4
etc...

$data = $_POST['data'];
foreach ($data as $tempone) {
  foreach ($tempone as $key=>$temptwo) {
   echo "$temptwo", "\n";
  }
  echo "<br>";
 }

How can I get those results and use them in an email?

$message .= "the forloop results here"

There's a few similar questions about but none using a Multidimensional arrays.

2
Contributors
2
Replies
12
Views
1 Year
Discussion Span
Last Post by cereal
0

This actually sorted it, not sure if it's right, but it works. Still open to suggestions if there's a better way to do it but I'll mark as solved (:

                foreach ($data as $tempone) {
  foreach ($tempone as $key=>$temptwo) {
   $message .= ''.$temptwo.''; 
  }
      $message .= '<br>';
 }
1

If you're using PHP 5.5+ then you could use array_column with implode(), for example:

<?php

// example contents
$_POST['data'][] = ['a' => 1];
$_POST['data'][] = ['a' => 2];
$_POST['data'][] = ['a' => 3];
//

$data = $_POST['data'];
$data = implode(' ', array_column($data, 'a'));

print $data;

That will print 1 2 3. Docs: http://php.net/array-column

Edited by cereal

Votes + Comments
Nice
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.