dongtang2376 2013-03-30 18:09
浏览 49
已采纳

如果数组中的任何值包含单独数组中的任何字符串,如何从数组中删除键?

I have an array, $search_results. Each key has multiple elements. I also have a single column array called $outofstock. If any of the elements within a particular key of $search_results exactly match any of the entries in $outofstock, I would like to remove the key, and re-arrange the key structure, so as to not have a gap in key ordering - and then create a new array of the same name: $search_results.

I've tried a few solutions found here - namely

But I can't seem to get them to match the text exactly and then re-create the array, while using array_filter to remove the entries I need to remove.

  • 写回答

1条回答 默认 最新

  • doujiexi1824 2013-03-30 18:34
    关注

    You can loop through one array and remove the index where you find string you are searching for.

    for($i=0;i$<count($outofstock);$i++){   
        foreach($search_result as $k=>$v){   
            if($outofstock[$i]==$v){    
                unset($search_result[$k]);
            }    
        }    
    }
    
    $search_result = array_values($search_result);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化