Ivan Ivan - 5 months ago 19
PHP Question

How to pick specificed values from array in PHP?

This is variable $msg returns this output from paypal response:

Array (
[mc_gross] => 7000.00
[protection_eligibility] => Ineligible
[address_status] => unconfirmed
[payer_id] => SEVC3VYVYC8NS
[tax] => 0.00
[address_street] => Minicraft 5
[payment_date] => 13:29:34 Jun 10, 2016 PDT
[payment_status] => Pending
[charset] => windows-1252
[address_zip] => 11580
[first_name] => Joe
[payer_email] => joe@hiskaya.com
)


I tried to get $msg['payment_date'] and $msg['payer_email'], then they return empty blank strings in email body, I don't know why.

EDITED FOR SOMEONE WHO WANTS REVELANT CODE:

I created my own lib which it can send email, it's my own function, not revelant.

$msg = print_r($request, true);
$pay_date = $msg['payment_date'];

sendMail([
'subject' => 'Payment has been received',
'body' => "Date: ".$pay_date.",
'to_email' => 'someone@ail.com',
'to_name' => 'Joe',
]);

Answer

According to manual

When the return parameter is TRUE, this function will return a string.

This means that $msg is a string. And definitely has no payment_date key.

I don't know why you assign $request value to another variable, you can use it:

sendMail([
  'subject' => 'Payment has been received',
  'body' => "Date: " . $request['payment_date'],
  'to_email' => 'someone@ail.com',
  'to_name' => 'Joe',
]);