PHP Questions Home

Categories

Arrays
Files
Forms
Functions
Images
MySQL
Numbers
Others
Strings
Website


PHP Functions

PHP Functions


More PHP

Top Questions
Ask a Question

How do I force a value to be treated as a number?


If you want to force a variable to be treated a certain way, for instance as an integer, you can "type cast" it as follows.

Here's an example:

<?php
$value 
= (int) "25atoz";
$multiple $value $value;
echo 
"$multiple";
?>


This will print '625' to the screen. Using the word (int) ensures PHP creates an integer variable with a value of '25' - otherwise it would create a string variable.



More numbers PHP Questions

How do I format a number with commas like a monetary value?
How do I round down a number?
How do I round up a number?
How do I work out the remainder of a division?
How do I generate a random number?