YALINQO:查询深层数组

时间:2015-08-22 03:03:31

标签: php linq yalinqo

Array
(
[0] => Array
    (
        [EndpointArn] => arn:aws:sns
        [Attributes] => Array
            (
                [Enabled] => true
                [Token] => APA91
                [CustomUserData] => Alcatel
            )

    )

[1] => Array
    (
        [EndpointArn] => arn:aws:sns:ap
        [Attributes] => Array
            (
                [Enabled] => true
                [Token] => APA91bGC
                [CustomUserData] => Oppo
            )

    )

)

我从源代码获取此数组。 我是yalinqo的新手,所以在尝试和错误后,我碰巧用这段代码打印CustomUserData:

$result= from($Model2['Endpoints'][0]['Attributes'])->select(function($np) { return $np; });

print $result->toArrayDeep()['CustomUserData']; 

现在我想根据我选择的CustomUserData打印EndpointArn,但我的代码不起作用。

这是代码:

print 
from($Model2['Endpoints'])
->select(function($np){ return $np['EndpointArn']; })
->where(function($np){return $np['Attributes']['CustomUserData'] == 'Oppo';})
->toArrayDeep()
;

错误讯息:

Warning: Illegal string offset 'Attributes' in /home/u
Warning: Illegal string offset 'CustomUserData' in /home/u  
Warning: Illegal string offset 'Attributes' in /home/u    
Warning: Illegal string offset 'CustomUserData' in /home/u

此代码:

print 
from($Model2['Endpoints'])
->select(function($np){ return $np['EndpointArn']; })
->where(function($np){return $np['Attributes']['CustomUserData'] == 'Oppo';})
;

错误讯息:

Catchable fatal error: Object of class YaLinqo\Enumerable could not be converted to string in

有人可以遮挡一些光吗?

感谢。

1 个答案:

答案 0 :(得分:1)

尝试和错误后,这是答案:

print 
from($Model2['Endpoints'])
->where(function($np){return $np['Attributes']['CustomUserData'] == 'Oppo';})
->select(function($np){ return $np['EndpointArn']; })
->toString()
;

结果

arn:aws:sns:ap