douwu8524 2013-10-02 04:50
浏览 64
已采纳

使用通配符调用爆炸数组中的所有字符串编号

After you explode a string, you can call the individual delimited words using something like:

$string[0]
$string[1]

etc.

Is there a way to call them all at once with a wildcard. I know this example doesn't work but something like this:

$string[*]

It's probably a dumb question; I'm just trying to save myself having to do 30 lines of code instead of one.

-- EDIT --

Here's what I have right now that's working for me:

$words = explode(' ',$string);
$thestuff = '';
if ($words[0] || $words[1] || $words[2] || $words[3] || $words[4] || $words[5] || $words[6] || $words[7] || $words[8] || $words[9] || $words[10] || $words[11] || $words[12] || $words[13] || $words[14] || $words[15] || $words[16] || $words[17] || $words[18] || $words[19] || $words[20] || $words[21] || $words[22] || $words[23] || $words[24] || $words[25] || $words[26] || $words[27] || $words[28] || $words[29] || $words[30]){
    $thestuff = do_shortcode($content);
}
return $thestuff;
}

But I'd like to be able to do it with $words[wildcard] or something simpler.

  • 写回答

1条回答 默认 最新

  • dongtan5558 2013-10-02 06:16
    关注

    You can use this code. You are using OR conditions so that you don't need to check every index.

    $words = explode(' ',$string);
    $thestuff = '';
    if (isset($words[0]) && !empty($words[0])){
        $thestuff = do_shortcode($content);
    }
    return $thestuff;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题