The first thing that came to mind is array_filter()
, actually it was preg_grep()
, but that doesn't matter:
$health = array_filter(glob("../health/*.php"), function($v) {
return false === strpos($v, 'index.php');
});
With preg_grep()
using PREG_GREP_INVERT
to exclude the pattern:
$health = preg_grep('/index.php$/', glob('../health/*.php'), PREG_GREP_INVERT);
It avoids having to use a callback though practically it will likely have the same performance
Update
The full code that should work for your particular case:
$health = preg_grep('/index.php$/', glob('../health/*.php'), PREG_GREP_INVERT);
$whathealth = $health[mt_rand(0, count($health) -1)];
include ($whathealth);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…