robert_gsfame Posted July 29, 2010 Share Posted July 29, 2010 how can i convert string type into integer like when using parseInt in javascript...however i use (int)$string but not working i have this $string1="10"; $string2="5"; and i wish to add both string ....using (int) still treat $string1 and $string2 as string so i get 105 as a result instead of 15 Quote Link to comment https://forums.phpfreaks.com/topic/209248-convert-string-into-integer/ Share on other sites More sharing options...
Alex Posted July 29, 2010 Share Posted July 29, 2010 If you want to get 105 then you want to treat them as strings and concatenate them. $string1="10"; $string2="5"; echo $string1 . $string2; // 105 Quote Link to comment https://forums.phpfreaks.com/topic/209248-convert-string-into-integer/#findComment-1092665 Share on other sites More sharing options...
robert_gsfame Posted July 29, 2010 Author Share Posted July 29, 2010 i want to get 15 not 105 Quote Link to comment https://forums.phpfreaks.com/topic/209248-convert-string-into-integer/#findComment-1092668 Share on other sites More sharing options...
Alex Posted July 29, 2010 Share Posted July 29, 2010 Oh, sorry, your post was confusing. In that case you can add them normally as PHP will automatically convert them to integers for you when performing the arithmetic. $string1="10"; $string2="5"; echo $string1 + $string2; // 15 Quote Link to comment https://forums.phpfreaks.com/topic/209248-convert-string-into-integer/#findComment-1092670 Share on other sites More sharing options...
robert_gsfame Posted July 29, 2010 Author Share Posted July 29, 2010 oops sorry.... i made a mistake...i can add those string directly n no need to change the type :P thx alex Quote Link to comment https://forums.phpfreaks.com/topic/209248-convert-string-into-integer/#findComment-1092672 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.