你好我想创建一个函数来检查一个etry是否包含一些单词。函数来检查数组strpos并返回一个数组
我的登录脚本我想创建一个函数,检查$ _POST是否有一些关键字。
therfor我曾经想过要创建一个包含我正在寻找这样的话数组:
$valid_value = value_check($a, $b);
if ($valid_value['a'] === true) {
//do something
}
if ($valid_value['b'] === true) {
//do something
}
非常感谢:
function value_check($a, $b){
$haystack = array ($a, $b)
$words = array ("abc", "def");
if(strpos($haystack, $words) === true) {
return ($a or $b, or both where strpos === true);
}
return false;
}
,我想通过调用该函数。
好的,为了澄清我的问题,我想缩短我的代码。而不是使用:
...else if ($a === "abc" || $a === "Abc" ) {
$errors['a'][] = "text";
}else if ($b === "def" || $a === "Def" ) {
$errors['b'][] = "text";
}
,我想我可以同时使用,检查容易,如果有数组中的一个特定字符串的函数做到这一点更舒服一点。希望现在会清楚。谢谢。
在想同样的事情... – Manatax 2013-02-22 18:31:55
检查'strpos'手册,它没有考虑数组作为参数。 – jeroen 2013-02-22 18:32:02
@MarkoD显然他不知道该怎么做,只需要一些帮助 – Peter 2013-02-22 18:32:33