Here’s what I want to do:
A variable $input can equal any of the following values:-2 -1 0 1 2
I need to process this input so that the only possible results are -1, 0, and 1. Numbers should be converted to whatever of those is closest, so -2 would turn into -1, 2 would turn into 1, but 1, 0, and -1 would all stay as they are.
I know how to do this using multiple lines, but I am sure there’s some way to do this with some set of calculations nested together.
Does that make sense? Let me know if I should clarify.
If you know you are definitely going to get only those values, you can use:
I would normally convert these to an integer explicity just in case.