duangao8359 2014-08-20 16:23
浏览 86
已采纳

使用explode过滤数组

My question is fairly simple. I have a column in my table labeled 'area' that appears like:

ma_south-coast
ma_south-caost
ma_north
ca_los-angelos
ca_los-angelos

I want to be able to select just the 'ma' ones. I am trying to do something such as:

$res_area = mysqli_query($connection,"select area from users");
        while ($row_state = mysqli_fetch_array($res_area)) {
        $state_exp = reset(explode("_", $row_state['area']));
        }

Printing $state_exp at this point would give me: mamamacaca which is good. But I want to filter so I only get the ma ones.

  • 写回答

4条回答 默认 最新

  • dongqian3198 2014-08-20 16:36
    关注

    The optimal solution could be :-

    $res_area = mysqli_query($connection,"select area from users WHERE area LIKE 'ma_*')";
            while ($row_state = mysqli_fetch_array($res_area)) {
            if(stripos(reset(explode("_", $row_state['area'])),'ma') !== FALSE)
            {
               $state_exp = reset(explode("_", $row_state['area']));
            }
          }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器