Mautic Community Forums

How to get usable values from $contact

How can I get usable values from Mautic objects like $contact?

$contact = $contactApi->get($id);

$contact is some kind of complicated multidimensional (?) array that contains a lot of information. What is the quickest, most efficient way to get useful bits like ‘firstname’ or ‘email’ from it?


You can narrow it down with this:

$fields = array_column($contact, ‘fields’);
$core = array_column($fields, ‘core’);
$firstname = array_column($core, ‘firstname’);

This then gives me the contact’s first name:

echo $firstname[0][‘value’];

So that’s the solution I guess. Or is this the wrong approach? Is there a more efficient way? Or a built-in Mautic solution I missed?