I have a positive number in PHP and I want to change it into a negative.
Therefore 3 to become -3.
How do I do this?
(other then $value = $value - $value - $value)
I think this works but it does not seem like a correct way to do this
function.
$value = - $value;
$value = -$value;
>
> $value = - $value;
Hmmm, still not behaving how I expect it to.
I have a function that adds a quantity to a column in Mysql. I wanted to use
the same function to deduct a value ( why rewrite it, just adapt it a bit)
However when I pass the value to the function
$value = - $value;
myAddFunction ($value)
//Function declation
myAddFunction ($value_to_add) {
$sql = "Update table SET field1= field1 + $value_to_add";
//run sql
}
Whenever I run this and echo the sql before running it always shows
$value_to_add as zero.
I'm sure I'm doing something else wrong.
> DOPE! I have found the rror in my code. Thanks.
I realize you fixed your error, but just to let you know,
changing the sign of a value will will also cause already
negative values to become positive. Just to be safe, you might
try something like this:
$value = -abs($value);
The above simply takes the absolute value of a value and makes it
negative.
--
~Curtis Dyer
<?php $x='<?php $x=%c%s%c;%cprintf($x,39,$x,39,10,10); ?>%c';
printf($x,39,$x,39,10,10); ?>