Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created August 28, 2015 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpfiddle/f822b069c55730d31600 to your computer and use it in GitHub Desktop.
Save phpfiddle/f822b069c55730d31600 to your computer and use it in GitHub Desktop.
[ Posted by Subash ] foreach in php
<?php
$rows = [
'row1' => [
'color' => 'red',
'width' => '550px',
'img' => 'http://www.google.com.au/images/srpr/logo11w.png'
],
'row2' => [
'color' => 'black',
'width' => '650px',
'img' => 'http://www.google.com.au/images/srpr/logo11w.png'
],
];
foreach ($rows as $key => $row) {
$color = $row['color'];
$image = $row['img'];
$width = $row['width'];
echo "<div style=\"background-color:$color;width:$width;\">";
echo "<img src=\"$image\">";
echo "</div>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment