Monday, 21 March 2016

Print array with alternate colour in PHP

CODE

<?php
$arr = array(
    'Pune'   => '#ff0000',
    'Nashik' => '#0000ff',
    'Mumbai' => '#00ff00'
);

foreach ($arr as $something => $colour) : ?>
    <p style="color:<?php echo $colour ?>"><?php echo $something ?></p>
<?php endforeach ?>

OUTPUT

Pune

Nashik

Mumbai


1 comment: