背景
我有两个名为$attributesand的数组$graphs。属性保存数据如下:
$attributes     = array('lat', 'long', '');
鉴于,$graphs包含这样的子数组:
$graphs = array(
    'bar_chart'  => array('gender', `lat`, `long`),
    'pie_chart'  => array('gender', 'location', 'pos_sentiment', 'neg_sentiment'),
    'line_chart' => array('pos_sentiment', 'neg_sentiment')
);
问题
我的$attributes数组是从我的数据库中的数据生成的,如果其中一个元素为空,则不返回包含其他属性的图形,这是我想要的。
我的问题
我想知道第一个数组 ( attributes) 是否在第二个数组 ( ) 中有任何元素graphs。我不希望考虑空字符串。
更新
意识到array_filter函数删除了空字符串后,我将它应用到我自己的代码上面并得到了我想要的结果。
代码是:
    foreach ($graphs as $key => $array)
    {
        if (count(array_intersect(array_filter($attributes), $array)) == count(array_filter($attributes)))
        {
            $solved[] = $key;
        }
    }