Is there any way to check the type of data, variables, etc. in PHP? Below you will learn how to check the data type.
※ Learn about PHP data types
The simplest way to do this is to use the gettype() function. gettype() returns the type of data with a built-in function. First, php has the following types.
unknown type
NULL
string
integer
array
object
bollean
...
There are various types as above. See below for an example of using getType.
※ See an example of the PHP gettype() function
This example shows the type of the variable $myStr shown below.
$myStr1 = 'abc'
$myStr2 = 100
$myStr3 = true
$myStr4 = NULL
echo gettype($myStr1);
echo gettype($myStr2);
echo gettype($myStr3);
echo gettype($myStr4);
When you execute the above code, you will see the following.
'string'
'integer'
'boolean'
'NULL'
So far, I've learned how to check the type in PHP. There is also a function to check the type, but there is also a function to specify and set the type. You can use the settype () function.
'개발 꿀팁 > PHP' 카테고리의 다른 글
Remove empty elements from PHP array (0) | 2018.01.16 |
---|---|
[PHP] Back to previous page (0) | 2018.01.16 |
[PHP] Removing duplicate values in arrays, Array_unique () (0) | 2018.01.16 |
How to import Amazon product descriptions, images, etc. with ASIN [Using AMAZON ASSOCIATES] (0) | 2018.01.16 |
(PHP) strpos로 문자열 포함되는지 검사하는 소스 (0) | 2016.08.29 |