php - check if $_POST is array?

前端 未结 8 609
独厮守ぢ
独厮守ぢ 2020-12-21 14:58

I know this may be a silly question, but I come across a snippet of php code that check if the $_POST is_array() before execute other functions.

相关标签:
8条回答
  • 2020-12-21 15:27

    $_POST is always defined as an array even it doesn't contain any key/value pairs.

    0 讨论(0)
  • 2020-12-21 15:27

    As already mentioned several times, $_POST is a superglobal that is always defined and always an array (unless overwritten).

    If you're attempting to test if something has been posted, you could use something like follows:

    if (count($_POST)) {
        // something has been submitted
    }
    

    To answer the main question, no, the is_array check is not required.

    0 讨论(0)
提交回复
热议问题