Vmi90 Posted November 26, 2006 Share Posted November 26, 2006 Ok, i want to take a variable, and add/subtract it to a constant number.The variable has commas in it, is there a way to take them out?Also, whats the code to add/subtract the variable to a constant? Link to comment https://forums.phpfreaks.com/topic/28534-math-problems/ Share on other sites More sharing options...
kenrbnsn Posted November 26, 2006 Share Posted November 26, 2006 You remove the commas with the [url=http://www.php.net/str_replace]str_replace()[/url] function.You can't add/subtract a variable from a constant, since then it wouldn't be a constant anymore. You can add/subtract a variable from a constant and store the results in another variable.If I were you, I would read the [url=http://www.php.net/manual/en/langref.php]Language Reference[/url] section of the manual. This should help answer your questions.Ken Link to comment https://forums.phpfreaks.com/topic/28534-math-problems/#findComment-130570 Share on other sites More sharing options...
.josh Posted November 26, 2006 Share Posted November 26, 2006 you are going to have to be more specific. $blah = "1,2,3";is that what you have? you can explode at the commas, creating an array with 3 seperate variables..but then what? are you wanting to add 1 2 and 3 together? add them to your constant, seperately? Link to comment https://forums.phpfreaks.com/topic/28534-math-problems/#findComment-130571 Share on other sites More sharing options...
Vmi90 Posted November 26, 2006 Author Share Posted November 26, 2006 lets say the variable is 1,200. I want to take away the , so it says 1200.then i wanted to add 100 to that variable would it be$newvar = ($oldvar + 100) ? Link to comment https://forums.phpfreaks.com/topic/28534-math-problems/#findComment-130589 Share on other sites More sharing options...
kenrbnsn Posted November 26, 2006 Share Posted November 26, 2006 Like I said earlier, use the str_replace() function to remove the commas:[code]<?php$var = "1,200";$newvar = str_replace(',','',$var) + 100;echo $var . ' ... ' . $newvar;?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/28534-math-problems/#findComment-130598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.