.Net int () is equivalent in PHP
3 answers
This should clear it:
<?php
header("Content-Type: text/plain");
$arr = array(-6, -6.2, -6.7, 5, 5.3, 5.8);
foreach ($arr as $v) {
printf("%f: (int) = %d, floor = %d, ceil = %d\n", $v, (int)$v, floor($v), ceil($v));
}
?>
outputs:
-6.000000: (int) = -6, floor = -6, ceil = -6
-6.200000: (int) = -6, floor = -7, ceil = -6
-6.700000: (int) = -6, floor = -7, ceil = -6
5.000000: (int) = 5, floor = 5, ceil = 5
5.300000: (int) = 5, floor = 5, ceil = 6
5.800000: (int) = 5, floor = 5, ceil = 6
Note: . Casting for int and floor()
doing different things.
Edit: Oh, you want to convert from string to int. One tip: when you ask questions like this, describe what the original function does. You will receive a faster and more understandable answer.
Also, keep in mind that PHP and .NET types work differently. For example:
$foo = '-234'; // string
$bar = $foo + 5;
print $bar; // -229
PHP has a complex type of juggling to automatically convert the type of variables as needed. This includes going to and from booleans, integers, floats, and strings as needed.
+1
source to share