PHP数组输出特定键和/或值

时间:2015-12-16 04:02:22

标签: php arrays api foreach crm

我想根据PHP数组中的键获取特定值。

我收到了大量不需要的语法。 我正在使用此库对Insightly CRM https://github.com/Insightly/insightly-php

进行API调用

代码:

<!DOCTYPE html>
<html>
<head>
<?php
    echo "<h1>PHP Insightly Test</h1>";
    require("insightly.php");
    $i = new Insightly('apikey');
    $contacts = $i->getContacts();
?>
<title></title>
</head>
<body>
<?php
    $array = array(); 
    foreach ($contacts as $contact)
    {
        $array[] = $contact;
    }
    print_r($array[1]);
?>
</body>
</html>

网页输出如下:

stdClass Object ( [CONTACT_ID] => 1234567 [SALUTATION] => [FIRST_NAME] => Frank [LAST_NAME] => Foster [BACKGROUND] => [IMAGE_URL] => http://dfvd [DEFAULT_LINKED_ORGANISATION] => [OWNER_USER_ID] => 343435 [DATE_CREATED_UTC] => 2015-11-22 21:46:25 [DATE_UPDATED_UTC] => 2015-11-22 21:52:19 [VISIBLE_TO] => EVERYONE [VISIBLE_TEAM_ID] => [VISIBLE_USER_IDS] => [CUSTOMFIELDS] => Array ( ) [ADDRESSES] => Array ( ) [CONTACTINFOS] => Array ( [0] => stdClass Object ( [CONTACT_INFO_ID] => 34353453 [TYPE] => EMAIL [SUBTYPE] => [LABEL] => Work [DETAIL] => email@email.com ) ) [DATES] => Array ( ) [TAGS] => Array ( ) [LINKS] => Array ( ) [CONTACTLINKS] => Array ( ) [EMAILLINKS] => Array ( ) )

我需要个人值

例如(名字/姓氏) - Frank Foster

我试过了print_r($array[1]['FIRST_NAME']);?但没有运气。想知道我是否需要编码或解码?不确定答案。

感谢。

2 个答案:

答案 0 :(得分:1)

使用时应使用“ - &gt;”访问对象属性。

print_r($array[1]->FIRST_NAME);

答案 1 :(得分:1)

您可以使用此语法回显FIRST_NAME:

echo $array[1]->FIRST_NAME;