Alternating table row colors from array

Views: 3 Last modified: September 17th, 2011 Comments: 0

A snippet, which can help you out alternating table row colors from a array.

$values = array('PHP' => 'Hypertext Preprocessor',
				'HTML' => 'Hypertext Markup language',
				'SGML' => 'Standard Generalized Markup Language',
				'XML' => 'Extensible Markup Language',
				'AJAX' => 'Asynchronous JavaScript and XML'
				);

// Set count variable to 0
$count = 0;

// Open table element
echo '<table>';

// Create your table rows and cells
foreach ($values as $key => $value)
{
	if ($count%2!=0):
		$color = '#FF6A00';
	else:
		$color = '#16A016';
	endif;

	echo '<tr bgcolor="'.$color.'"><td>'.$key.'</td><td>'.$value.'</td></tr>';
	// Count each time 1 to $count
	$count++;
}
// Close your table element
echo '</table>';
Attachments 1 image(s) & 0 video(s) found.
VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)

    Mail this!

    To: From:Sum {0+6} =  
    Anything to add ?

        You must be logged in to post a comment.