From a function we use, it returns an array like this.
array (size=1)
96 =>
array (size=10)
'customerName' => string 'ClutchPoints, Inc.' (length=18)
'email' => string 'nish@clutchpoints.com' (length=21)
'additionalEmails' => null
'addressStreet' => string '11390 W. Olympic Blvd. #420' (length=27)
'addressLine2' => null
'addressCity' => string 'Los Angeles' (length=11)
'addressState' => string 'CA' (length=2)
'addressPostalCode' => string '90064' (length=5)
'addressCountry' => string 'US' (length=2)
'companyName' => string 'ClutchPoints, Inc.' (length=18)
I cannot figure out a way to get the inside array’s value to print in the applications. Is there any way to get the values out?
Thank you in Advanced.
$data = array_map(function ( $obj ){
return array(
'customerName' => $obj->name,
'email' => $obj->company_contact->email,
'additionalEmails' => $obj->company_contact->secondaryContactEmail,
'addressStreet' => $obj->company_contact->addressLine1,
'addressLine2' => $obj->company_contact->addressLine2,
'addressCity' => $obj->company_contact->city,
'addressState' => $obj->company_contact->stateOrProvince,
'addressPostalCode' => $obj->company_contact->zipOrPostalCode,
'addressCountry' => $obj->company_contact->country,
'companyName' => $obj->name
);
}, $customer_data);
I tried using array_map
it also returns an array with a different index number.
>Solution :
Since it’s always only one element, you can use current to get first element of array, no matter of its key:
$element = current($data); // ALTERNATIVE: array_shift($data);
echo $element['additionalEmails'];