The code is:
echo " AS " . $index - 10 . " - " . $index . " SA ";
$index
is an integer.
The output is:
-10 - 0 SA
The expected output is:
AS -10 - 0 SA
What am I missing?
Try this instead.
echo " AS ", $index - 10 . " - " . $index . " SA ";
Yea well that works. But why does it happen? Is my syntax incorrect? Is there a rule you can't put words before mathematic operation?
I defer to http://php.net/manual/en/language.operators.precedence.php as you did ask it to concatenate " AS " to $index.
Sorry if you feel shortchanged here. It's one of those questions that pop up a lot.
In addition, you can also do:
echo " AS " . ($index - 10) . " - " . $index . " SA ";
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.