WeCodeAcademy

PHP Data Types

PHP has string, integer, float, boolean, array, object and NULL. var_dump shows a value with its type; gettype returns the type name.

ExamplePHP
<?php
var_dump("text");
var_dump(42);
var_dump(3.14);
var_dump(true);
var_dump([1, 2]);
var_dump(null);
echo gettype(7.0) . "\n";
var_dump((int) "12abc");
var_dump("10" + 5);
var_dump(0.1 + 0.2 == 0.3);
Output
string(4) "text"
int(42)
float(3.14)
bool(true)
array(2) {
  [0]=>
  int(1)
  [1]=>
  int(2)
}
NULL
double
int(12)
int(15)
bool(false)

Note the last line: decimals are stored in binary, so 0.1 + 0.2 is not exactly 0.3. Compare floats with care.

Quick check

What does var_dump show?

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.