tip:
instead of writting
you can do this type of stuff
Code: Select all
<?php
$foo -= $bar;
$foo += $bar;
$foo %= $bar;
$foo /= $bar;
?>
etc....
the only way to pass in the operator as a variable would be to use eval(), which is a bad bad thing to use usually. its slow, and has security issues. Much better would be to do this type of stuff:
Code: Select all
<?php
if ($operator === '+') {
$foo += $bar;
} elseif ($operator === '-') {
$foo -= $bar;
} // etc....
?>
but in the end, using a class, or at least a set of functions, will be the best answer.
if you want a nice little shopping cart class i have one. Youll need to learn how to use classes.