Take the tour ×  I was wondering what is the best way to
typecast a value from one type to another.  Which variant should
we use:    1. intval($value);   2. settype($value, 'int')   3.
(int)$value  All of them produce same result.  share|improve
this question add comment  5 Answers  up vote 10 down vote
accepted  saves one function call compares to intval($value) and
settype($value, 'int').  And (int)$value is clean enough, so I
prefer this way.  When you need to use intval($value) is that
when you need to use the specified base for the conversion (the
default is base 10). intval accepts a second parameter for the
base for the conversion.  share|improve this answer Under what
cases do they have differing behavior? –  Antimony Aug 8 '12 at
3:08 Just what I was searching for, thanks! –  s.webbandit Aug 8
'12 at 4:08 add comment  I prefer using  share|improve this
answer I see what you did there –  Scuzzy Aug 8 '12 at 4:10 I
was all like WTF DOWNVOTE ... then I got it. Nice :) –  rdlowrey
Aug 8 '12 at 4:26 add c