只获取一组值,通过PHP循环和数组



我将使用这段代码尝试在PHP中循环一个数组

$url='https://api.hubapi.com/form-integrations/v1/submissions/forms/e053ea53-0dae-4cbb-8343-f4ad7bbcaecd?hapikey=8b9998be-1082-4520-a503-c981bab5c57f';
$result = file_get_contents($url);
$arrays = json_decode($result,true);
foreach($arrays['results'][0]['values'] as $item) {
echo $item['value'];

}

我只得到一组值而应该有两个

输出:GermanyADP, ECM IntroPMI Document Solutions, inc . munich http://www.pmi-ny.comOctober 241200webinar这是一个testbob@hotmail.comLink合作伙伴事件

这些是第二组值。第一个在哪里?

你可以这样处理json数据:

$url='https://api.hubapi.com/form-integrations/v1/submissions/forms/e053ea53-0dae-4cbb-8343-f4ad7bbcaecd?hapikey=8b9998be-1082-4520-a503-c981bab5c57f';
$json = json_decode( file_get_contents( $url ) );
$res=$json->results;
foreach( $res as $obj ){
$values=$obj->values;

foreach( $values as $o ){
echo $o->name . ' ' . $o->value . ' ' . $o->objectTypeId . '<br />';
}           
}

将输出:

country Germany 0-2
title_no_dropdown ADP, ECM Intro 0-1
presented_by PMI Document Solutions, Inc. 0-1
city Munich 0-1
website http://www.pmi-ny.com 0-1
start_date October 24 0-1
time 1200 0-1
type Webinar 0-1
description this is a test 0-2
email bob@hotmail.com 0-1
link Link to partner event 0-1
country United States 0-2
title_no_dropdown ADP, Work Smart from the Start 0-1
state NY 0-1
presented_by PMI Document Solutions, Inc. 0-1
city Corning 0-1
website http://www.pmi-ny.com 0-1
start_date September 24 0-1
time 1000 0-1
type Infoseminar 0-1
description This is a test 0-2
email likwid2@hotmail.com 0-1
link Link to partner event 0-1

最新更新