Detect field type sent in POST PHP

0

Is there a way to identify the type of field that is coming in a post?

If it's Text or Array?

Example:

I have listbox (select multiple) and text fields in html, and in it the user can select values or not, I have a function where I check the values of the fields before proceeding, but when I have this type of field in between I get the problem , I needed to treat it differently when it comes in the post.

    
asked by anonymous 02.10.2018 / 17:10

1 answer

2

There is the gettype() function that returns a string that identifies the data type that is the variable passed to the parameter, even if it is an array. You can use this to handle your code.

For example, a gettype([1,2]); would return 'array' , gettype(1); would return 'integer' , gettype('teste'); would return 'string' , and so on. It is also possible to do this for values coming via post, such as gettype($_POST['campo']); .

More in the official documentation > > link

    
02.10.2018 / 17:17