Post the context of your question.
If you answer a question post the context of your answer.
I often see questions that say, something like
This doesn't work. It echoes "no" when it should be showing "yes"
echo ($a > $b ? "yes" : "no");
Then there's all sort of answers about how to solve this issue using type casting, and then after all the answers come in, it turns out there's some giant problem at the root of it all about how the variables $a
and $b
are being created, and it turns out the original question should have been.
I have this array of items and prices and I want to see if one item is more expensive than the other. I have coded this so far:
<?php
$prices = array("candy" => 1.50, "lettuce" => 0.50);
$a = "candy";
$b = "lettuce";
echo "Is $a more expensive than $b?:\n\n";
echo ($a > $b ? "yes" : "no");
?>
But it's printing "no" even though 1.50 > 0.50. What's going on?
When you're trying to get help, it's often tempting to just post the one line that is giving you the error, but the problem is often larger than that.
It often takes more time to figure out what actually is the meaningful context of a question, and it takes effort to figure out how to describe the whole story, but in the long run, the better able an asker is to explain all of what's going on, all of the inputs, what they mean, the desired output, why its all being done in the first place, etc., etc., the better answers they'll get.
The same idea applies to answers. Don't just solve the syntax error. If the user is getting an error because they are not dealing with things correctly (character encoding, type casting, etc) then mention that. Sometimes this is difficult because of the way the question is asked, but it's very valuable to provide a context for your answer if possible.