Hi,
What does type casting mean in PHP? Explain with an example?
Type casting in PHP
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
SenthilkumarRank #387 · 6.5K reputationPosted Mar 25, 2012, 4:44 AM EDT
Please go through this url:
http://www.electrictoolbox.com/type-casting-php/
http://www.phpro.org/tutorials/PHP-Type-Casting.html
Satyapriya NayakRank #47 · 31.5K reputationPosted Mar 25, 2012, 5:16 AM EDT
PHP automatically store the data and interprets according to itself. Type casting is a way to assign the variable according to your need and requirement and not allowing PHP to assign it automatically. To specify the type, it can be used like:
$newint = (int) $var1;
$newfloat = (float) $var1;
$newstring = (string) $var1;
The value in the variable on the right side of the equal sign is stored in the variable on the left side as the specified type.
Thanks