Fundamentally – no. That’s about as easy as it gets. You might rewrite it a bit shorter/cleaner, but the idea will be the same. This is how I would write it:
$c = true; // Let's not forget to initialize our variables, shall we?
foreach($posts as $post)
echo '<div'.(($c = !$c)?' class="odd"':'').">$post</div>";
Related Contents:
- Only last link of css is taking effect
- HTML form string error [closed]
- How Can I add HTML And CSS Into PDF [closed]
- Seo Friendly URL results in CSS IMG and JS not working
- How to write specific CSS for mozilla, chrome and IE
- Hiding a Div using php
- How to import/include a CSS file using PHP code and not HTML code?
- Multiple javascript/css files: best practices?
- Scroll bar for Datalist in HTML5
- Continuing overflowed text in a different div?
- HTML PHP Progress Bar
- How to wrap long lines without spaces in HTML?
- Send email with PHP from html form on submit with the same script
- Multiple inputs with same name through POST in php
- How to display HTML tags as plain text [duplicate]
- Preserve Line Breaks From TextArea
- Understanding the “post/redirect/get” pattern
- How to upload images into MySQL database using PHP code
- How to read if a checkbox is checked in PHP?
- POST an array from an HTML form without javascript [duplicate]
- How to set HTML value attribute (with spaces)
- Opening/closing tags & performance?
- Converting HTML to plain text in PHP for e-mail
- Send value of submit button when form gets posted
- How to write html code inside , I want write html code within the PHP script so that it can be echoed from Backend [closed]
- Scrape web page contents
- How can I run a PHP script inside a HTML file?
- How to replace text URLs and exclude URLs in HTML tags?
- How do i run PHP inside CSS
- How to prevent multiple inserts when submitting a form in PHP?
- RegExp to strip HTML comments
- HTML: Changing colors of specific words in a string of text
- Why cannot change checkbox color whatever I do? [duplicate]
- Convert all types of smart quotes with PHP
- PHP – Secure member-only pages with a login system
- line breaks in a textarea
- file_get_contents() give me 403 Forbidden
- PHP – empty $_POST and $_FILES – when uploading larger files
- CodeIgniter – why use xss_clean
- How to set selected value of HTML select box with PHP
- Single and double quotes together as HTML attribute value?
- onbeforeprint() and onafterprint() equivalent for non IE browsers
- GET vs. POST Best Practices
- mysqli_query() expects at least 2 parameters, 1 given in? [duplicate]
- PHP simple foreach loop with HTML [closed]
- Correct indentation of HTML and PHP using Vim
- Colorizing Windows command line output from PHP
- how do I get all checkbox variables even if not checked from HTML to PHP?
- Escape HTML to PHP or Use Echo? Which is better?
- HREF=”” automatically adds to current page URL (in PHP). Can’t figure it out