Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php - check if $_POST is array?

Tags:

arrays

php

global

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.

Now I guess that $_POST should be always an associative array or not? is this check really needed? and why?

like image 882
Julie Rokk Avatar asked Aug 29 '26 13:08

Julie Rokk


2 Answers

If it hasn't been changed in some manner like

$_POST = 'not array';

then it is array ;-)

like image 182
zerkms Avatar answered Sep 01 '26 03:09

zerkms


$_POST is always an array, they're probably checking if a certain $_POST value is an array.

<input name="test" /> $_POST['test'] is not an array

<input name="test[]" /> $_POST['test'] is an array

like image 32
Wesley Murch Avatar answered Sep 01 '26 04:09

Wesley Murch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!