Let s say my $_POST
variable looks like:
<?php
Array
(
[user_ID] => 65
[action] => editpost
[originalaction] => editpost
[post_author] => 154
[empl_bd_dd] => 6
[empl_bd_mm] => 5
[empl_bd_yy] => 1987
[empl_gen] => 1
[empl_height] => 155
[empl_weight] => 61
[empl_arra] => 2
[save] => Update
[post_it] => 2
[empl_pay] => J77
[empl_cust] => Married
[empl_lang] => Array
(
[0] => EN
[1] => FR
)
[empl_rent] => 1
[name] => Jimmy Nathan
[empl_text] => Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sed interdum leo. Sed et elit quam, tempor placerat neque. Nullam sapien odio, egestas iaculis dictum ut, congue ullamcorper tellus.
[empl_sk_0] => 6
[empl_sk_1] => 7
[empl_sk_2] => 5
)
?>
各位可以看到,我把我的所有形式变数预先定在<代码>empl_上。 没有必要逐一具体说明所有这些内容,我如何从<代码>_POST将所有形式变数输入一个成本最低的、希望可行的阵列? 是否有PHP阵列功能或组合,我可以加以利用?
与<代码>CSS一样,如果你能够选择使用<代码>>empl的类别的所有要素,则使用<代码>[类别*=”empl_>,那么,我就能够以这种方式与PHP的阵列钥匙,例如。
$empl_post = $_POST[ empl_* ]
<>strong>EDITED ANSWER - imptediation to @chris swer:$_POST
must be the first debate to array_intersection_key
, e.g:
$empl_POST = array_intersect_key($_POST, array_flip(preg_grep( /^empl_/ , array_keys($_POST))));