adspace


How to convert strings to numbers in php?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between htmlentities() and htmlspecialchars()?

1089


What is difference between static and final in php?

1107


hello all, I need some sample placement papers in lion bridge.. can anyone help me?

2174


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

1063


How to calculate the difference between two dates using php?

1142


What is the current stable version of php?

1122


how to detect a mobile device using php

1172


How to create a web form?

1109


What is the current stable version of php? What advance thing in php7?

1093


Explain me is it possible to destroy a cookie?

1025


Which variable declarations within a class is invalid in php?

1046


What is trait in php?

1065


Name and explain five of the PHP error constants?

1032


How can we extract string "pcds.co.in" from a string "https://info@pcds.co.in" using regular expression of php? More on reg can you explain

1076


sort term descripttion form, report and uery

2254