How to convert strings to numbers in php?



How to convert strings to numbers in php?..

Answer / Asha Gupta

To convert a string to a number in PHP, you can use the `(int)`, `(float)`, or `(boolean)` casts. Here's an example for each method:n`n// Using (int)n$str = "123456";n$num = (int)$str;nn// Using (float)n$str = "123.456";n$num = (float)$str;nn// Using (boolean) (converts to 0 if the string is empty or contains non-numeric characters)n$str = "123abc";n$num = (boolean)$str;n`

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More PHP Interview Questions

Explain the casts allowed in PHP?

1 Answers  


how many type of url?

1 Answers  


Which is better wamp or xampp?

1 Answers  


Is null function in php?

1 Answers  


Seeking a PHP skilled programmer, with knowledge of MySQL Database, Javascript and AJAX. CSS and HTML is a plus. Temporary job for 2 months. Possibility of extending the contract (depending on how good you are). Location: Delhi. Start: ASAP Contact me at boney@portlane.com together with your CV.

0 Answers   Eniro,


Tell me what kind of things have you done on the social side?

0 Answers  


What is sorting php?

1 Answers  


What are the security measures we have to take for our site not to hack by others.

3 Answers   Infosys, Torque Infotech,


How many types of errors in php?

1 Answers  


Why do we use csrf token?

1 Answers  


How to get number of elements in an array?

1 Answers  


Explain PHP?

1 Answers  


Categories