【发布时间】:2020-09-09 13:35:25
【问题描述】:
打印值时出现错误无法使用类型的对象 MongoDB\BSON\ObjectId 作为数组
这是我的 print_r 数据
stdClass Object
(
[_id] => MongoDB\BSON\ObjectId Object
(
[oid] => 5f55f95815a8508e2deac8dd
)
[title] => Consumers to Gain as Telcos Cut Broadband Rates
[summary] => Consumers are set to benefit from a broadband
[newsSources] => Array
(
[0] => stdClass Object
(
[title] => Consumers to Gain as Telcos Cut Broadband Rates
[articleId] => 003a0593-f0c3-11ea-98d1-1418779a6e32
[link] => https://myimpact.in/clipj_admin.php?id=95c14189533fa7c87a8ce6752cae40f5
[type] => print
[source] => The Economic Times - Kolkata
)
[1] => stdClass Object
(
[title] => Data Plans Coming Much Cheaper with Telcos at War, Again
[articleId] => 3c4052f6-f0ac-11ea-959b-0068ebdc2fd0
[link] => https://myimpact.in/clipj_admin.php?id=95126ad546a574dd8233c2b0365d5f01
[type] => print
[source] => The Economic Times - Mumbai
)
我正在尝试从两个数组访问 [Source]
这是我的代码 -
foreach($cursor as $row){
// echo"<pre>";
// print_r($row);
foreach($row as $data) {
foreach($data['newsSources'][0] as $k) {
echo $k->source ;
}
}
}
【问题讨论】: