To evaluate the positive and negative signs so that all positive symbols are ignored and two negatives equal a positive, you can perform a replacement.
Code: (Demo)
$signed_number_strings = ["--1", "---33", "+-444"];
foreach ($signed_number_strings as $string) {
var_dump((int)preg_replace('~\++|-\+*-\+*~', '', $string));
}
Output:
int(1)
int(-33)
int(-444)
The logic behind the pattern is to first match/remove 1 or more consecutive +
signs, OR a -
sign followed by zero or more +
followed by a -
(and absorbing any trailing +
signs). If there are any fringe cases that my pattern doesn't correctly handle, please update your question and leave me a comment.
p.s. The extension of my 2nd branch with \+*
is an attempt to optimize the pattern so that it doesn't have to restart the pattern. It could have been written as ~\++|-\+*-~
which would be slightly less strain on the eyeballs. (Demo)