我能';t在PHP中获取JSON输出
我从curl请求中获得了以下响应输出我能';t在PHP中获取JSON输出,php,arrays,json,curl,Php,Arrays,Json,Curl,我从curl请求中获得了以下响应输出 Array ( [code] => 200 [message] => Message history obtained successfully. [data] => Array ( [0] => Array ( [id] => 3390257 [aggr
Array
(
[code] => 200
[message] => Message history obtained successfully.
[data] => Array
(
[0] => Array
(
[id] => 3390257
[aggregator_id] => 25
[user_id] => 184279092
[message_id] => 7784285
[ext_message_id] => 152127f68b2000031bf6584fa8494a7b
[send_date] => 2016-01-05 09:54:17
[dest_address] => 8476099160
[dest_country] => 1
[dest_type] => 1
[source_address] => 8
[source_country] => 1
[source_type] => 2
[message] => Heres how others are earning up to an extra $300/day simply by using their phone or working from home Click Here now: http://bit.ly/1PIiVZl
[transaction_id] =>
[message_status] => 14
[message_schedule_id] => 59335
[last_modified_date] => 2016-01-05 09:54:52
[last_modified_user_id] => 184279092
[keyword_id] => 1459
)
[1] => Array
(
[id] => 3390261
[aggregator_id] => 25
[user_id] => 184279092
[message_id] => 7784289
[ext_message_id] => 152127f6c36000171df5874efba398b4
[send_date] => 2016-01-05 09:54:17
[dest_address] => 6188892860
[dest_country] => 1
[dest_type] => 1
[source_address] => 8
[source_country] => 1
[source_type] => 2
[message] => Heres how others are earning up to an extra $300/day simply by using their phone or working from home Click Here now: http://bit.ly/1PIiVZl
[transaction_id] =>
[message_status] => 14
[message_schedule_id] => 59335
[last_modified_date] => 2016-01-05 09:54:52
[last_modified_user_id] => 184279092
[keyword_id] => 1459
)
[2] => Array
(
[id] => 3390265
[aggregator_id] => 25
[user_id] => 184279092
[message_id] => 7784293
[ext_message_id] => 152127f65dd000031bf6584fa84949af
[send_date] => 2016-01-05 09:54:17
[dest_address] => 2032415751
[dest_country] => 1
[dest_type] => 1
[source_address] => 8
[source_country] => 1
[source_type] => 2
[message] => Heres how others are earning up to an extra $300/day simply by using their phone or working from home Click Here now: http://bit.ly/1PIiVZl
[transaction_id] =>
[message_status] => 14
[message_schedule_id] => 59335
[last_modified_date] => 2016-01-05 09:54:52
[last_modified_user_id] => 184279092
[keyword_id] => 1459
)
[3] => Array
(
[id] => 3390270
[aggregator_id] => 25
[user_id] => 184279092
[message_id] => 7784298
[ext_message_id] => 152127f6a2a0001a8d8e4ef0eebbbe5d
[send_date] => 2016-01-05 09:54:17
[dest_address] => 3106193605
[dest_country] => 1
[dest_type] => 1
[source_address] => 8
[source_country] => 1
[source_type] => 2
[message] => Heres how others are earning up to an extra $300/day simply by using their phone or working from home Click Here now: http://bit.ly/1PIiVZl
[transaction_id] =>
[message_status] => 14
[message_schedule_id] => 59335
[last_modified_date] => 2016-01-05 09:54:52
[last_modified_user_id] => 184279092
[keyword_id] => 1459
)
)
)
现在我想获得数组值,比如
$keyword\u id=1459
,但我无法访问数组。假设此响应存储在名为$response
的变量中,下面是一些访问数组元素的示例
$response['data'][0]['id'] // 3390257 (id of 1st data element)
$response['data'][1]['dest_address'] // 6188892860 (dest_address of 2nd data element)
$response['data'][3]['keyword_id'] // 1459 (keyword_id of 4th data element)
您还可以迭代数据元素并按如下方式打印ID
foreach ($response['data'] as $i => $element) {
echo "The id of element " . $i . " is " . $element['id'] . "\n";
}
您可以通过foreach循环获取关键字_id。在数组上运行foreach循环,并通过关键字id索引获取数据
foreach($array as $value){
$keyword_id = $value['keyword_id'];
}
这将为您提供关键字id