integer: Converting to integer

Converting to integer

  • To explicitly convert a value to integer, use either the (int) or (integer) casts.
  • In most cases the cast is not needed, since a value will be automatically converted if an operator, function or control structure requires an integer argument.
  • A value can also be converted to integer with the intval() function.
  • If a resource is converted to an integer, then the result will be the unique resource number assigned to the resource by PHP at runtime.
  • FALSE will yield 0 (zero), and TRUE will yield 1 (one).
  • When converting from float to integer, the number will be rounded towards zero.
  • NULL is always converted to zero (0).
  • The behaviour of converting to integer is undefined for other types. Do not rely on any observed behaviour, as it can change without notice.

Related concepts

integer: Converting to integer — Structure map

Clickable & Draggable!

integer: Converting to integer — Related pages: