Click to See Complete Forum and Search --> : values from Multi-Array into mail
Jerico
10-09-2008, 05:37 PM
Hi
I have a multidimensional array storing values that I need to add to the body of an email - however since the number of values can be any amount, how do I loop through the array and add each iteration to the body string? Is there a way of concatenating a loop?
confused:confused:
chazzy
10-09-2008, 06:19 PM
you'll need to tell us a bit more about your array, but i don't see any reason why you can't do something like this...
$str = "";
$bodyArray = $my_array['key_for_body'];
for($i = 0;$i<count($bodyArray);$i++) {
$str .= $bodyArray[$i];
}
Znupi
10-10-2008, 07:21 AM
You can use PHP's builtin print_r (http://php.net/print-r) function. Like this:
$string = print_r($array, true);
:)
ariell
10-10-2008, 10:54 AM
Looping multidi arrays is, for instance, possible like this:
Let's say you have a 2-dim array like this:
<?php
$t = array();
$t[0][0] = "a";
$t[0][1] = "b";
$t[1][0] = "y";
$t[1][1] = "z";
$emailbodychar = '';
foreach ($t as $v1)
foreach ($v1 as $v2)
$emailbodychar .= $v2.' ';
?>
However, in the example above, you'll get a pretty long "character" with just a space between the values read from array. You'll just need to customize this, but I know nothing faster (at the moment.)
Best from the south.