Coercion is when you tell PHP which type to use when interpreting a value. Usually PHP figures out the type based on context. Coercion is when instead you want PHP to interpret based on a type of your own choosing.

You may be wondering …


If I use coercion on a particular type of data what will the new value be?


PHP follows a set of rules for this. Find out what the rule is for the type of coercion you are doing. Look it up in a PHP book or the PHP manual.

Ways to coerce:

  • use a conversion function
  • use a type cast

Conversion functions:

  • settype()
  • intval()
  • floatval()
  • strval()

To use a type cast put the name of the type in parentheses to the left of the expression. Type names:

  • integer
  • int
  • float
  • double
  • real
  • boolean
  • bool

About samehramzylabib

See About on
This entry was posted in Coding, PHP Data Value Types and tagged , . Bookmark the permalink.


Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s