PHP subtracting strlen($string)

678 Views Asked by At

I would like to invert the value of strlen, how would i do this?

i.e.

$string = "123";

echo strlen($string);

3

i get the expected result when i do:

echo strlen($string)*-1;

-3

however, when i do:

$var = strlen($string)*-1;

echo $var;

i get nada, as in nothing.

2

There are 2 best solutions below

1
On BEST ANSWER
$string = "123";

echo strlen($string) * -1; // -3
echo 0 - strlen($string);  // -3
1
On

it would just be echo -strlen("123"); or echo strlen("123")*-1;. Both of those return -3