casting - Typecasting vs function to convert variable type in PHP -


is there difference between typecasting , using function convert variable type?

(float)$var vs. floatval($var)

if there are, when 1 of should used instead of other?

there's no difference in resulting value, just:

  • (float) language feature , quick
  • floatval() incurs overhead of function call (minimal, nonetheless...)
  • floatval() function can used in ways (float) cannot, e.g. array_map('floatval', $foo)

the last point is, believe, main reason floatval's existence: each casting operation has function equivalent, can useful in circumstances.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -