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

时间:2017-11-16 10:51:08

标签: php arrays multidimensional-array foreach agile-crm

我试图从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
    ) 
)

我想回应" 5686812383117312"来自" [id] => 5686812383117312" (上面数组中的第4行)

我已经尝试过" foreach"声明,但我对它的专业知识是有限的,似乎无法做到正确。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

要访问ID字段,您应该:

  1. 获取阵列的第一把钥匙
  2. 访问必填字段
  3. 阵列:

    select INPUT__FILE__NAME from table
    

    PHP:

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