Here’s an example of the array I need help with (let’s call it $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 )
)
I know how to step thru this using foreach as follows: (NOTE: edited to show what I’m actually doing at the cost of simplifying the question).
$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);
So what I’d like to is step thru the array three at a time.
ok I think I understand the question enough to answer, if I dont understand the need. There are probably many ways to do it. one way may be something like
if I understand correctly. There may be a faster or better way. I think it is an unorthodox solution because I dont understand why you would send 3 at the time.
note this is not a complete solution… for example it would shoot an error if the array length was not evenly divisible by 3…
on thinking about this the first comment was the best solution ARRAY CHUNK – PHP.NET
EDIT: solution changed to use array_chunk with simple for loops to navigate them.