How do I check the data type of a variable

In PHP, you can check the data type of a variable using the gettype() function or the var_dump() function. Below is an example of how to use both functions to check the data type of a variable:

<?php $var1 = 10; $var2 = "Hello, World!"; $var3 = 3.14; $var4 = true; // Using gettype() echo "Data type of var1: " . gettype($var1) . "<br>"; echo "Data type of var2: " . gettype($var2) . "<br>"; echo "Data type of var3: " . gettype($var3) . "<br>"; echo "Data type of var4: " . gettype($var4) . "<br>"; // Using var_dump() var_dump($var1); var_dump($var2); var_dump($var3); var_dump($var4); ?>

PHP data type gettype var_dump variable type