I'm sure this is easy with Arrays but I don't seem to get how to do it as I need multiple sets of data
relevant PHP for 1 set, there may be 3-4 of these
$title="Slide Title";
$desc="Slide description";
$buttonlink="Button Link";
$button="Button";
PHP foreach of the sets (obviously this doesn't work because I don't have the set defined and don't know how to define it in the correct way)
<?php foreach ($set[] ){ ?>
<div class="item">
<img src="<?php $slider ?>" alt="">
<div class="container">
<div class="carousel-caption">
<h1><?php echo $title ;?></h1>
<p><?php echo $desc ;?></p>
<p><a class="btn btn-lg btn-primary" href="<?php echo $butonlink ;?>" role="button"><?php echo $button ;?></a></p>
</div>
</div>
</div>
<?php } ?>
So basically how can I define each of the sets so I can use it in a single foreach statement that will output my desired set of variables.
Simply array task, see this example:
<?php
$sets = array (
array (
'img' => 'file.png',
'title' => 'Slide Title 1',
'desc' => 'Slide description 1',
'buttonlink' => 'Button Link 1',
'button' => 'Button 1'
),
array (
'img' => 'file.png',
'title' => 'Slide Title 2',
'desc' => 'Slide description 2',
'buttonlink' => 'Button Link 2',
'button' => 'Button 2'
)
);
foreach ($sets as $key => $set) {
?>
<div class="<?php echo $key == 0 ? 'item active' : 'item'; ?>">
<img src="<?php echo $set['img'] ?>">
<div class="container">
<div class="carousel-caption">
<h1><?php echo $set['title'] ;?></h1>
<p><?php echo $set['desc'] ;?></p>
<p><a class="btn btn-lg btn-primary" href="<?php echo $set['butonlink'] ;?>" role="button"><?php echo $set['button'] ;?></a></p>
</div>
</div>
</div>
<?php
}
?>