douzhankui0758 2014-08-25 15:45
浏览 17
已采纳

每个结果的PHP不包括数组中的值

I queried a table into an array but I would like to exclude certain values from one of the columns as to spits out each row. For example.

foreach($results as $row)
{
         if($row['sku'] != "sku-1"){
             echo $row['sku']." ";
         }
}

So lets say the table has 4 rows with a value of sku-1, sku-2, sku-3 and sku-4. The above Foreach code would echo out "sku-2 sku-3 sku-4". Is there a way I can make an array of what values I would want to exclude? Like I'd have an array called $skuarray = "sku-2, sku-4" and instead of

if($row['sku'] != "sku-2" || $row['sku'] != "sku-4"){

have that $skuarray in there where it'll echo "sku-1, sku-3"? Thanks!

EDIT

I could somehow exclude it when I query it. I'm querying it from table SKUTABLE and the column is SKU. The problem is I need to exclude unique values from column SKU so I thought if there was an easy way to just throw in all the ones I want to exclude into an array that'd be great.

  • 写回答

4条回答 默认 最新

  • dsiftnc99059 2014-08-25 15:50
    关注

    Use in_array:

    $skuarray = array("sku-2", "sku-4");
    
    foreach($results as $row)
    {
             if(!in_array($row['sku'], $skuarray)){
                 echo $row['sku']." ";
             }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?