我确信这是一个简单的解决方案 - 我写了这个函数,并认为我会尝试使用 array_walk 函数而不是单独测试每个字符串。我假设 array_walk 函数的结果是假的,但它返回 1...如果它没有找到匹配项,我如何让它测试所有字符串并返回假?谢谢
class {
function endsWith($value,$key,$haystack)
{
$length = strlen($value);
if ($length == 0) {
return true;
}
return (substr($haystack, -$length) === $value);
}
function thing()
{
$email = "should@returnfalse.info";
$arr = array("@test.net","@test.org.uk","@test.co.uk","@test.com");
echo array_walk($arr,array($this,"endsWith"),$email);
}
}