190319m9 Posted December 2, 2008 Share Posted December 2, 2008 <?phpif (date("H")>"19" && <"22") echo "Good Morning!"; elseif (date("H")>"00" && <"04" && date("i")<"30") echo "Good Afternoon!"; else echo "Enjoy, your time."; ?> Link to comment Share on other sites More sharing options...
jeffman Posted December 2, 2008 Share Posted December 2, 2008 1. Simply put, you need an L-value for every comparison. There is no shorthand, although at times I'd like there to be. Thus:($val < 5 && $val > 0)2. It's no big deal in a little routine like this, but if you find yourself calling the same function several times just to get the same value, it's more efficient to call it just once and store the value in a variable. Thus: $val = func($arg);if ($val < 5 && $val > 0) { // do something} elseif ($val < -5 && $val < 0) { // do something else} Link to comment Share on other sites More sharing options...
190319m9 Posted December 13, 2008 Author Share Posted December 13, 2008 Whats the error in this snippet?? <?php$d=date("H");if ($d>"19" && <"22")echo "Good Morning!";elseif ($d>"00" && <"04")echo "Good Afternoon!";elseecho "Enjoy, your time.";?> Link to comment Share on other sites More sharing options...
boen_robot Posted December 13, 2008 Share Posted December 13, 2008 As said, there must always be a Left value for every comparrison. There's no shorthand. <?php$d=date("H");if ($d>"19" && $d<"22")echo "Good Morning!";elseif ($d>"00" && $d<"04")echo "Good Afternoon!";elseecho "Enjoy, your time.";?>Funny thing though, you can see what happens when there IS a shorthand for something (like "Left value") - people get confused. Link to comment Share on other sites More sharing options...
jeffman Posted December 13, 2008 Share Posted December 13, 2008 Just to make it crystal clear, then, in case anyone searches these hallowed archives:The term L-value is short for Left-value. The term is used with reference to the assignment and comparison operators. Left and right refer to the sides of such an operator. So in the expression a = 5, a is the left, or L-value, and 5 is the right value. (I've never used the term R-value in actual practice, but I suppose it exists.)The most common L-value error is assigning a value to a constant or to the return value of a function, such that 4 = 7 and getCheese() = 3 are illegal statements.Most modern programming languages require an L-value for every comparison operator, even when the operators are used in combination. So this is illegal (x < 10 && > 5). The legal expression is (x < 10 && x > 5).Here's a case that seems to defy the rule: a = s = d = f = g = h = 5. This expression assigns the value of 5 to all those variables. A way of understanding it is to say that s through h function as both L- and R-values. Link to comment Share on other sites More sharing options...
190319m9 Posted December 13, 2008 Author Share Posted December 13, 2008 Thanks for the replies. Got the point. Quite fundamental, will be in memory forever now! Mistakes teach you in a very good way. Link to comment Share on other sites More sharing options...
redwall_hp Posted December 13, 2008 Share Posted December 13, 2008 EDIT: Oops, never mind. I missed your last reply, Manik. Disregard this post. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.