PHP's typeof – gettype()

Quite often you may need the ability to check what type of data type a variable is.

In most programming languages this is possible to do and is usually called typeof().
PHP too has a way to check this, it is called gettype() and it’s so simple to use.

All you have to do is echo out a call to gettype() with your variable as the first argument.

Like so:

function foo($bar) {
echo gettype($bar);
}
foo("stringVar);
//echo’s "
stringVar";
foo($arrayVar);
//echo’s "
array";

In the above script we create a function called foo which has 1 argument, it can take any data type so we call it twice, one with a string argument and secondly with an array argument.

Read the official documentation on gettype here.


Share This Article

Related Posts

Comments

There are no comments on this entry.

Trackbacks

There are no trackbacks on this entry.

Add a Comment

Required

Required

Optional

Latest Domains

1. teledyne.com
(5 hours ago)
2. ngtechonology.com
(6 hours ago)
3. nonude.in
(6 hours ago)
4. spicyhunt.com
(12 hours ago)
5. whpromotions.co.uk
(15 hours ago)
6. seslihome.com
(17 hours ago)
7. sesliislam.com
(19 hours ago)
8. woopra.com
(1 day ago)
9. wapdam.com
(1 day ago)
10. 193.105.134.194
(1 day ago)

Services

PHP MySQL Apache Flash Air Java C++ Python