在php中验证数组值

在php中验证数组值,php,Php,我想验证从文本字段插入的数组中的值。用户是否已插入其全名。在插入数据库之前,我想确认所有值只包含文本、数字和长度为20个字符的空格 请提出任何答案 我有$g8_sub_vali[]=$\u POST[“g8_sub$I”]作为一个数组,包含100多个字段。我想检查所有字段是否以格式插入 此代码检查$array的每个元素,使其仅包含拉丁字符、数字和空格。字符串的长度介于2到20个符号之间。不区分大小写: <?php $array = array( array(), "value", "val

我想验证从文本字段插入的数组中的值。用户是否已插入其全名。在插入数据库之前,我想确认所有值只包含文本、数字和长度为20个字符的空格

请提出任何答案


我有
$g8_sub_vali[]=$\u POST[“g8_sub$I”]
作为一个数组,包含100多个字段。我想检查所有字段是否以格式插入

此代码检查$array的每个元素,使其仅包含拉丁字符、数字和空格。字符串的长度介于2到20个符号之间。不区分大小写:

<?php
$array = array(
array(),
"value",
"value 2",
"vagh-% ^",
"texttexttexttexttexttexttexttexttexttexttexttext",
);

check_elements($array);

function check_elements(&$array)
// {{{
{
    foreach($array as $value)
    {
        if (!is_array($value))
        {
            if (preg_match('/^[a-z0-9\s]{2,20}$/i', $value))
            {
                print $value." good\n";
            }
            else
            {
                print $value." bad\n";
            }
        }
        else
        {
            check_elements($value);
        }
    }
}
// }}}

请用示例数据显示数组您的代码如何?我已经编辑了文本passthrough
array\u filter
当我插入代码时,我得到了这个警告:preg\u match()希望参数2是字符串,数组在C:\xampp\htdocs\school\styles\adm\test.php行中给出33@user2642907这取决于您的数据结构。var_dump您正在插入的数组并将结果放入您的问题中,这样我可以更正答案这是var_dump数组的结果(16){[0]=>array(0){}[1]=>string(6)“adfads”[2]=>string(5)“afkdj”[3]=>string(5)“adfjk”[4]=>string(6)“adfklj”=>string(5)“adfda”[6]=>string(0)”[7]=>string(0)”“[8]=>string(0)”[9]=>字符串(0)“[10]=>字符串(0)”“[11]=>字符串(0)”“[12]=>字符串(0)”“[13]=>字符串(0)”“[14]=>字符串(0)”“[15]=>字符串(0)”}@user2642907我们可以创建一个递归函数,用于检查嵌套数组。我更新了代码。但是行动取决于你对这种情况的要求。@user2642907好吧,我希望你能做些努力。我给了你正则表达式和整体设计。剩下的就交给你了。
value good
value 2 good
vagh-% ^ bad
texttexttexttexttexttexttexttexttexttexttexttext bad