Php Post数组中的嵌入式数组
所以这可能很简单,但我似乎可以让它在我这方面发挥作用。我目前有一个嵌入式阵列,如下所示:Php Post数组中的嵌入式数组,php,arrays,foreach,Php,Arrays,Foreach,所以这可能很简单,但我似乎可以让它在我这方面发挥作用。我目前有一个嵌入式阵列,如下所示: $array = array ( array( $_SESSION['Contact']['Name'], $_SESSION['Contact']['Email'] ... ) ); 我的会话数组中有大约30个字段。使用上面的示例,我必须手动列出每个会话数组项。所以,我的问题是,有没有一种方法可以迭代Sessions数组以获得相同的上述结果
$array = array (
array(
$_SESSION['Contact']['Name'],
$_SESSION['Contact']['Email']
...
)
);
我的会话数组中有大约30个字段。使用上面的示例,我必须手动列出每个会话数组项。所以,我的问题是,有没有一种方法可以迭代Sessions数组以获得相同的上述结果
$array = array (
array(
foreach ($_SESSION as $key => $value){
$value.", ";
}
)
);
//我的电子邮件/CSV功能
function create_csv_string($data) {
// Open temp file pointer
if (!$fp = fopen('php://temp', 'w+')) return FALSE;
// Loop data and write to file pointer
foreach ($data as $line) fputcsv($fp, $line);
// Place stream pointer at beginning
rewind($fp);
// Return the data
return stream_get_contents($fp);
}
function send_csv_mail ($csvData, $body, $to = 'xx@xxx.com', $subject = 'Test email with attachment', $from = 'zz@zzz.com') {
// This will provide plenty adequate entropy
$multipartSep = '-----'.md5(time()).'-----';
// Arrays are much more readable
$headers = array(
"From: $from",
"Reply-To: $from",
"Content-Type: multipart/mixed; boundary=\"$multipartSep\""
);
// Make the attachment
$attachment = chunk_split(base64_encode(create_csv_string($csvData)));
// Make the body of the message
$body = "--$multipartSep\r\n"
. "Content-Type: text/plain; charset=ISO-8859-1; format=flowed\r\n"
. "Content-Transfer-Encoding: 7bit\r\n"
. "\r\n"
. "$body\r\n"
. "--$multipartSep\r\n"
. "Content-Type: text/csv\r\n"
. "Content-Transfer-Encoding: base64\r\n"
. "Content-Disposition: attachment; filename=\"file.csv\"\r\n"
. "\r\n"
. "$attachment\r\n"
. "--$multipartSep--";
// Send the email, return the result
return @mail($to, $subject, $body, implode("\r\n", $headers));
}
send_csv_mail($array, "Hello World!!!\r\n This is simple text email message.");
我想出来了。答案很简单,而且几乎太明显了
$array = array (
$_SESSION['Purchase']
);
你为什么要这样掩埋会话数组?我用它来创建一个CSV文件,然后通过电子邮件将结果发送给我自己。你不能在不掩埋会话变量的情况下创建CSV吗?IDK,我是个新手。我在上面粘贴了我的函数。我在网上找到了这个函数,它很有效,所以我坚持使用它。问题是你有嵌套数组吗?您的示例显示了一个单独的$_会话['contact'],但是否也有一个$_会话['contact2']和$_会话['contact3'],每个会话都有成员的“姓名”和“电子邮件”?