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?

Recommended Answers

All 4 Replies

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?

In addition, you can also do:

echo " AS " . ($index - 10) . " - " . $index . " SA ";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.