数学和操作员行为

$id = $_GET['id'];
$oldprice = $_SESSION['price'][$id-=1];

This works but unfortunately now $id whenever referenced is one less than it should be where I need it.

I've tried $modified_id = $id-=1; to try and keep the original $id variable and create a new 'modified' variable with the value of $id minus 1 but it all seems to have the same effect of modifying the original. What am I doing wrong?

Thanks.

If you do not want to change the value of $id, use

$oldprice = $_SESSION['price'][$id-1];

You're not keeping the original $id in $modified_id = $id-=1;; $id will be 1 less.

Try

$id = $_GET['id'];
$oldprice = $_SESSION['price'][$id-1];

Try this now

$id = $_GET['id'];
$saved_id = $id - 1;
$oldprice = $_SESSION['price'][$saved_id];