O'Reilly logo

Core PHP Programming, Third Edition by Leon Atkinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

G.5. Expressions

Write conditional expressions so that they read naturally aloud. Sometimes eliminating a not operator (!) will make an expression more understandable. Use parentheses liberally to resolve ambiguity. Using parentheses can force an order of evaluation. This saves the time a reader may spend remembering precedence of operators.

Keep each line simple. The trinary operator (x ? 1 : 2) usually indicates too much code on one line. if..elseif..else is usually more readable. Don't sacrifice clarity for cleverness.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required