1

What, exactly, is the purpose of the intval() function for a base-10 calculation? Isn't it the exact same as a typecast, just slower? In all of my Googling, I haven't found a single benefit. What am I missing?

Nathanael
  • 6,435
  • 4
  • 29
  • 50
  • See also http://stackoverflow.com/questions/1912599/is-there-any-particular-difference-between-intval-and-int (not quite a duplicate) – John Carter Jun 26 '12 at 03:41

2 Answers2

5

intval() lets you specify a base to convert from.

$decimal_value = intval("FF", 16)

For simple base-10 conversions, there's no reason to use intval().

Amber
  • 477,764
  • 81
  • 611
  • 541
  • 1
    If you constrain your question like that, then yes, there's no reason to use `intval()`... but that's kind of like asking "what's the point `preg_replace()` if I'm just doing basic string replacement, it's like `str_replace()` but slower". – Amber Jun 26 '12 at 03:38
1

intval() can accept a base parameter, casting to an int cannot.

Ned Batchelder
  • 345,440
  • 70
  • 544
  • 649