Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:获取错误无法将MongoDB\BSON\ObjectId类型的对象用作数组?_Php_Arrays_Mongodb - Fatal编程技术网

PHP:获取错误无法将MongoDB\BSON\ObjectId类型的对象用作数组?

PHP:获取错误无法将MongoDB\BSON\ObjectId类型的对象用作数组?,php,arrays,mongodb,Php,Arrays,Mongodb,打印值时,我收到错误,无法将类型为MongoDB\BSON\ObjectId的对象用作数组 这是我的打印数据 stdClass Object ( [_id] => MongoDB\BSON\ObjectId Object ( [oid] => 5f55f95815a8508e2deac8dd ) [title] => Consumers to Gain as Telcos Cut Broadban

打印值时,我收到错误,无法将类型为MongoDB\BSON\ObjectId的对象用作数组

这是我的打印数据

    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 ;
                              
                        }
                 }
 }
foreach($cursor作为$row){
//回声“;
foreach($data->newsSources as $item)
    echo $item->source;
//打印(行); foreach($行作为$数据){ foreach($data['newsources'][0]作为$k){ echo$k->source; } } }
$data
是一个对象。您需要使用箭头语法来访问属性