I have a payment function that emails me whenever a transaction occurs, the issue is it emails me too much data, and not all of it is relevant. The payment itself is processed by Authorize API (which is also whats returning this data).
function sent_mail($data = array()) {
$out = "";
foreach ($data as $k => $value) {
if (is_array($value)) {
foreach ($value as $key => $v) {
$out .= ucwords($key) . ' Name : ' . $v . "<br/>";
}
} else {
$out .= ucwords($k) . ' : ' . $value . "<br/>";
}
}
$msg = "<h2><strong>Receipt Of Payment</strong></h2>" . "<br/><br/>";
$msg .= "$out";
$to = '[email protected]';
$subject = 'New Payment';
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
@mail($to, $subject, $msg, $headers);
}
The email I get, includes these fields:
DataValue, DataDescriptor, InvoiceID, Amount, Item_name, Item_Desc, FirstName, LastName, Email, Website, Country, Zip, Terms, TransID, Card_Holder
Where as, the only data I need is
InvoiceID, Amount, Item_name, FirstName, LastName, Email, Website
I've not sure how to limit this, create a skip?
$datathen you have a slew of functions for filtering$datafor theforeach():array_diff*(),array_udiff*(),array_intersect*()andarray_uintersect*(). But the goal is like a variation of Sumurai8's answer, you either whitelist or blacklist to limit the array to the keys that you want in the email.