这是我需要帮助的数组示例(我们称之为 $MY_ARRAY)
Array (
[0] => Array ( [NAME] => 1351449606472 [EMAIL] => aaa@yadda.com [ID] => 996774000001224477 )
[1] => Array ( [NAME] => 1351449605330 [EMAIL] => bbb@yadda.com [ID] => 996774000001224473 )
[2] => Array ( [NAME] => 1351449604318 [EMAIL] => ccc@yadda.com [ID] => 996774000001224469 )
[3] => Array ( [NAME] => 1351449603089 [EMAIL] => ddd@yadda.com [ID] => 996774000001224465 )
[4] => Array ( [NAME] => 1351449602046 [EMAIL] => eee@yadda.com [ID] => 996774000001224461 )
[5] => Array ( [NAME] => 1351449600883 [EMAIL] => fff@yadda.com [ID] => 996774000001224457 )
[6] => Array ( [NAME] => 1351449599840 [EMAIL] => ggg@yadda.com [ID] => 996774000001224453 )
)
我知道如何使用 foreach 完成此操作,如下所示:(注意:已编辑以显示我实际在做什么,但以简化问题为代价)。
$aws = curl_init();
$url = "https://email.us-east-1.amazonaws.com/";
curl_setopt($aws, CURLOPT_URL, $url);
curl_setopt($aws, CURLOPT_RETURNTRANSFER, true);
//process data
foreach($MY_ARRAY as $X)
{
//set-up email
$MY_ARRAY = $X['EMAIL'];
$ID = $X['ID'];
$SUBSCRIBER_ENCODE = rawurlencode($SUBSCRIBER);
$HELLO = "";
if (strlen($X['NAME']) == 0)
{
$HELLO = "Subscriber,<br /><br />";
}
else
{
$HELLO = $X['NAME'].",<br /><br />";
}
$EMAIL_BODY_ENCODE = rawurlencode($HELLO.$BODY);
//tune curl vars
$DATE = gmdate('D, d M Y H:i:s e');
$HASH = hash_hmac('sha1', $DATE, $AWSPRI, true);
$KEYS = base64_encode($HASH);
$headers = array();
$headers[] = "Host: email.us-east-1.amazonaws.com";
$headers[] = "Content-Type: application/x-www-form-urlencoded";
$headers[] = "Date: ".$DATE;
$auth = "AWS3-HTTPS AWSAccessKeyId=".$AWSPUB;
$auth .= ",Algorithm=HmacSHA1,Signature=".$KEYS;
$headers[] = "X-Amzn-Authorization: ".$auth;
$MAIL = "Action=SendEmail&Source=".$XROM_ENCODE."&ReturnPath=".$BOUNCE_ENCODE."&Destination.ToAddresses.member.1=".$SUBSCRIBER_ENCODE."&Message.Subject.Data=".$SUBJECT_ENCODE."&Message.Body.Html.Data=".$EMAIL_BODY_ENCODE;
curl_setopt($aws, CURLOPT_POSTFIELDS, $MAIL);
curl_setopt($aws, CURLOPT_HTTPHEADER, $headers);
$resp = curl_exec($aws);
}
//complete log and close curl
curl_close($aws);
所以我想要的是一次通过三个数组。