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
To use a type cast put the name of the type in parentheses to the left of the expression. Type names: