What is the output of the following code snippet? $a = ‘5’ + 2; echo gettype($a);

PHP Intermediate Hard

PHP Intermediate — Hard

What is the output of the following code snippet? $a = ‘5’ + 2; echo gettype($a);

Key points

  • Arithmetic operators trigger type juggling
  • Numeric strings are cast to numeric types during arithmetic
  • The result of integer addition is an integer

Ready to go further?

Related questions