I have a mail call that returns JSON in one of two ways:
$json1 = '{"found":1,"email":"email1@domain.com","error":"","rd":"email2@domain.com"}';
$json2 = '{"found":1,"email":"email1@domain.com,email2@domain.com","error":"","rd":"email3@domain.com,email4@domain.com"}';
In the first case, the parameters emailand rdhave only one email address. In the second case, the same two parameters have several recipients.
I need to receive emails from each parameter and add it to an existing array:
$recipients = array('support@domain.com');
I can make it work with a variable $json1using the following code:
array_push($recipients, $obj->{'rd'}, $obj->{'email'});
The second JSON option is placed less often, but I still need the same code to work in both instances. And currently, if I use the above code with second JSON data, it returns this:
Array
(
[0] => support@sculpturehospitality.com
[1] => email3@domain.com,email4@domain.com
[2] => email1@domain.com,email2@domain.com
)
. - , ?
:
http://sandbox.onlinephpfunctions.com/code/24c4a1eaea98566b65cd36e221dd1f185e820ea6