shamuraq Posted April 15, 2009 Share Posted April 15, 2009 Hi all... Thanx for all your responses regarding my query to manipulating integer. I have slight problem that i hope you can help me out with... How then do i convert a negative integer to a positive integer. I'm doing an algebraic equation and i am very sure you already know that when you bring a positive integer over the other side of the equal sign (2x-3y + 6 = 0) they become a negative integer (2x-3y = -6) and vice versa. Anyway proper syntax for this? Quote Link to comment https://forums.phpfreaks.com/topic/154212-manipulating-integers-ii/ Share on other sites More sharing options...
Mchl Posted April 15, 2009 Share Posted April 15, 2009 Huh? $a = 5; echo -$a; // -5 Quote Link to comment https://forums.phpfreaks.com/topic/154212-manipulating-integers-ii/#findComment-810702 Share on other sites More sharing options...
shamuraq Posted April 15, 2009 Author Share Posted April 15, 2009 thanx Mchl... what about the other way ard? Quote Link to comment https://forums.phpfreaks.com/topic/154212-manipulating-integers-ii/#findComment-810714 Share on other sites More sharing options...
Mchl Posted April 15, 2009 Share Posted April 15, 2009 Same... $a = -5; echo -$a; //5 Quote Link to comment https://forums.phpfreaks.com/topic/154212-manipulating-integers-ii/#findComment-810721 Share on other sites More sharing options...
shamuraq Posted April 15, 2009 Author Share Posted April 15, 2009 thanx Mchl... but because i need to solve it later... does <echo> function store the output as variable or integer? what do you think of: $z4= -1*$z2; echo $z4; Please give me your comments... Quote Link to comment https://forums.phpfreaks.com/topic/154212-manipulating-integers-ii/#findComment-810731 Share on other sites More sharing options...
Daniel0 Posted April 15, 2009 Share Posted April 15, 2009 Math in PHP works like the math you would normally use: -(-x) = x I'm doing an algebraic equation and i am very sure you already know that when you bring a positive integer over the other side of the equal sign (2x-3y + 6 = 0) they become a negative integer (2x-3y = -6) and vice versa. I suppose that it's a popular saying that you "move" it, but that's not really what's going on. You can perform the same operation on each side of the equal sign (except division and multiplication by zero). This means that if you have a=b, then a+x=b+x. 1=1 <=> 1+2=1+2 <=> 3=3. You just need both of the sides to evaluate to the same. So if you have 2x-3y+6=0, then you know that subtraction is the opposite arithmetic operation of addition, thus they negate each other. So because of the above rules, you are allowed to say 2x-3y+6-6=0-6 <=> 2x-3y-0=-6 <=> 2x-3y=-6. You knew that you had to do -6 to get the +6, because that would make it +/-0, which is redundant so you can just remove it. It helps to know that. thanx Mchl... but because i need to solve it later... does <echo> function store the output as variable or integer? what do you think of: $z4= -1*$z2; echo $z4; Please give me your comments... echo is a language construct, and not a function. Either way, it takes a string as argument. PHP is weakly typed, so scalar non-string values will implicitly be converted to strings for usage in a string context. It's only converted for that purpose though and isn't stored anywhere. Quote Link to comment https://forums.phpfreaks.com/topic/154212-manipulating-integers-ii/#findComment-810737 Share on other sites More sharing options...
shamuraq Posted April 15, 2009 Author Share Posted April 15, 2009 echo is a language construct, and not a function. Either way, it takes a string as argument. PHP is weakly typed, so scalar non-string values will implicitly be converted to strings for usage in a string context. It's only converted for that purpose though and isn't stored anywhere. I swear i honestly wish i could fully grasp and understand your statement but i really appreciate the prompt attention i am getting from pros like you guys... Thanx again Daniel and the gurus... Quote Link to comment https://forums.phpfreaks.com/topic/154212-manipulating-integers-ii/#findComment-810802 Share on other sites More sharing options...
Daniel0 Posted April 15, 2009 Share Posted April 15, 2009 I would advice you to read this chapter: http://php.net/manual/en/langref.php It explains type conversion and the other syntactical aspects of PHP. Do feel free to ask if there is anything you do not understand Quote Link to comment https://forums.phpfreaks.com/topic/154212-manipulating-integers-ii/#findComment-810816 Share on other sites More sharing options...
shamuraq Posted April 16, 2009 Author Share Posted April 16, 2009 I'll definitely look into it... Thanx again Daniel0... You guys are the helpful pros... Quote Link to comment https://forums.phpfreaks.com/topic/154212-manipulating-integers-ii/#findComment-811226 Share on other sites More sharing options...
.josh Posted April 19, 2009 Share Posted April 19, 2009 just multiply by -1. If it's a positive number, it will become negative. If it's negative, it will become positive. Quote Link to comment https://forums.phpfreaks.com/topic/154212-manipulating-integers-ii/#findComment-813606 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.