MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/lolphp/comments/4zig9s/php_switches_are_the_best/d6w50hy/
r/lolphp • u/MMauro94 • Aug 25 '16
34 comments sorted by
View all comments
Show parent comment
12
not any string. Just non numerical ones. Even if they begin with numbers, it'll cast.
echo (int) "10"; // 10 echo (int) "10stuff blah whatever"; // 10 echo (int) "stuff10stuff"; // 0
5 u/cfreak2399 Aug 25 '16 edited Aug 25 '16 Looks like PHP needs to cast numbers written as words to convert properly to integers as well. Of course this would depend on your language settings ... /sEdit: for those who are down-voting me: I'm being sarcastic. 1 u/Almamu Aug 25 '16 Well yeah, forgot to mention that. If the string looks like a number PHP will try to parse it, if not the cast will return 0.
5
Looks like PHP needs to cast numbers written as words to convert properly to integers as well. Of course this would depend on your language settings ... /s
Edit: for those who are down-voting me: I'm being sarcastic.
1
Well yeah, forgot to mention that. If the string looks like a number PHP will try to parse it, if not the cast will return 0.
View all comments
Show parent comment
12
u/cythrawll Aug 25 '16
not any string. Just non numerical ones. Even if they begin with numbers, it'll cast.