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.

图片转代码服务由CSDN问答提供 功能建议

在分解字符串后,您可以使用以下内容调用单个分隔的单词: \ ñ

 <代码> $串[0] 
 $的字符串[1] 
上  
 
 

时 有一种方法可以使用通配符立即调用它们。 我知道这个例子不起作用,但是这样:

  $ string [*] 
   
 
 

它是 可能是个愚蠢的问题; 我只是想节省自己不得不做30行代码。

- 编辑 -

这就是我所拥有的 现在,这对我有用:

  $ 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] || $ 单词[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; 
} 
   
 
 

但我希望能够用$ words [通配符]或更简单的东西来做。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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;
    }
    
    打赏 评论

相关推荐 更多相似问题