从 AgileCRM 提供的多维数组中获取特定值

Get a specific value from a multidimensional array provided by AgileCRM

我正在尝试从 AgileCRM 获取第一个交易 ID。

使用时:

$test = json_decode($deal, true);
print_r($test);

我得到以下结果:

Array ( 
[0] => Array ( 
    [colorName] => WHITE 
    [id] => 5686812383117312 
    [apply_discount] => 
    [discount_value] => 0 
    [discount_amt] => 0 
    [discount_type] => Value 
    [name] => New Home Loan 
    [contact_ids] => Array ( 
        [0] => 5645056174194688 
    ) 
    [custom_data] => Array ( 
    ) 
    [products] => Array ( 
    ) 
    [description] => New Lead 
    [expected_value] => 0 
    [milestone] => New Loan 
    [probability] => 10 
    [close_date] => 1521192269 
    [created_time] => 1510824270 
    [milestone_changed_time] => 0 
    [entity_type] => deal
    [notes] => Array ( 
    ) 
    [note_ids] => Array ( 
    ) 
    [note_created_time] => 0 
    [pipeline_id] => 5719238044024832 
    [archived] => 
    [lost_reason_id] => 0 
    [deal_source_id] => 0 
    [total_deal_value] => 0 
    [updated_time] => 1510824270 
    [isCurrencyUpdateRequired] => 1 
    [currency_conversion_value] => 0 
    [tags] => Array ( 
    ) 
    [tagsWithTime] => Array ( 
    ) 
    [contacts] => Array ( 
        [0] => Array ( 
            [id] => 5645056174194688 
            [type] => PERSON 
            [properties] => Array ( 
                [0] => Array ( 
                    [type] => SYSTEM 
                    [name] => first_name 
                    [value] => piet 
                ) 
                [1] => Array ( 
                    [type] => SYSTEM 
                    [name] => last_name 
                    [value] => pompies 
                ) 
                [2] => Array ( 
                    [type] => SYSTEM 
                    [name] => name 
                    [value] => 
                ) 
            ) 
        ) 
    ) 
    [owner] => Array ( 
        [id] => 5178546118721536 
        [domain] => domainname 
        [email] => myemail@email.com 
        [phone] => 
        [name] => Piet Pompies 
        [pic] => https://d1gwclp1pmzk26.cloudfront.net/img/gravatar/48.png 
        [schedule_id] => Piet Pompies
        [calendar_url] => https://homeside.agilecrm.com/calendar/Piet_Pompies
        [calendarURL] => https://homeside.agilecrm.com/calendar/Piet_Pompies
    ) 
)

)

我想从“[id] => 5686812383117312”(上面数组中的第 4 行)回显“5686812383117312”

我试过 "foreach" 陈述,但我的专业知识有限,似乎无法正确表达。

任何帮助将不胜感激。

为了访问 ID 字段,您应该:

  1. 获取数组的第一个键
  2. 访问必填字段

数组:

Array ( //$test
  [0] => Array (  //first key [0] 
      [colorName] => WHITE 
      [id] => 5686812383117312  //the required field ['id']
      [apply_discount] => 

PHP:

$test = json_decode($deal, true);
print_r($test);

echo $test[0]['id']; //Output: 5686812383117312