using a foreach loop to initialize variables

后端 未结 4 778
抹茶落季
抹茶落季 2021-01-16 08:22

I have built an empty associative array whos keynames refer to submitted post data. I can capture the postdata just fine, but I run into trouble trying to instantiate varia

4条回答
  •  感情败类
    2021-01-16 08:47

    You're not accessing $_POST at all, so all you're doing is taking some array members you defined yourself, filtering them for harmful POST characters (why would you attempt to inject your own code?) and then creating a new array from those self-defined key values.

    If I'm guessing right at what you want, it should be this:

    foreach(array_keys($insArray) as $key) {
        $insArray[$key] = stripslashes(filter_input(INPUT_POST, $_POST[$key]));
    }
    

    The use of stripslashes suggests that you're on a braindead version of PHP which has magic_quotes enable. You should upgrade to a modern version of PHP and/or turn them off.

提交回复
热议问题