douduan6731 2017-01-21 23:18 采纳率: 0%
浏览 31
已采纳

仅显示与PHP不匹配的内容

I'm trying to use a multiple foreach and if statements to give me a list of list of people that have not been matched. I have the below code, I am able to get this to successfully give me a list of people it does match.

What I want to do is it echo each the ID from the $tenant_id foreach that have not been found in the $value2 foreach, am I doing something wrong? It will only output nothing?

foreach($array_93 as $value) {
    $tenant_id = $value['id'];
    $limit = 0;
    foreach($obj->response->entries as $value2) {
        if($limit==1) break;
        if ($value2->{100} == 'true' && $value2->{114} == $tenant_id) 
            {echo $value['id']; // This should echo ID's that have not been found.}
            $limit++;
        }
    }
};

UPDATE >>

After continuing to try and get this working I have got to this point, I am able to to use this to show which ID's are all 'n' as per screenshot after. The first one is all n's so this has not matched, how can I now make just the ones with all n's ID show?

foreach($array_93 as $value) {
echo '<b>'.$value['id'].'</b>';
echo '<br />';

foreach($obj->response->entries as $value2) {
    if (strpos($value2->{114}, $value['id']) === false) 
        {
        echo '<i>n</i>';
    } else {
        echo '<b>Y</b>';
    }  
}
echo '<br />';
};

enter image description here

  • 写回答

2条回答 默认 最新

  • dongxiao1591 2017-01-21 23:30
    关注

    Use a flag with Y-found state:

    foreach($array_93 as $value) {
        $Yfound = false;
    
        foreach($obj->response->entries as $value2) {
            if (strpos($value2->{114}, $value['id']) !== false) {
                $Yfound = true;
            }
        }
        if(!$Yfound) {
            echo $value['id'] . ' has n`s only<br>';
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测