for each Example 1 caption and 3 occurrences for the source map
What am I doing wrong?
Images Array
$imgsArray = array(
'image1-small.jpg', 'image1-medium.jpg', 'image1-large.jpg',
'image2-small.jpg', 'image2-medium.jpg', 'image2-large.jpg',
'image3-small.jpg', 'image3-medium.jpg', 'image3-large.jpg'
); // sometimes more pictures too
Captions Array
$imgCaption = array('Adam','Peter','Susi');
the code
foreach($imgsArray as $files => $img) {
$first_char = substr($img,0,strpos($img,"-")); // delete from hyphen to the last string
if ($first_char != $last_entry) {
echo '<p>This is '.$imgCaption[$files];
echo '<ul>';
echo '<li>'.$first_char.'-small.jpg</li>';
echo '<li>'.$first_char.'-medium.jpg</li>';
echo '<li>'.$first_char.'-large.jpg</li>';
echo '<li>'.$imgCaption[$files].'</li>';
echo '</ul>';
echo '<i>Ciao, '.$imgCaption[$files].'</i><br>---</p>';
}
$last_entry = $first_char;
}
unexpected
This is Adam
- image1-small.jpg
- image1-medium.jpg
- image1-large.jpg
- Adam
---
This is Notice: Undefined offset: 3 in...
- image2-small.jpg
- image2-medium.jpg
- image2-large.jpg
- Notice: Undefined offset: 3 in...
---
This is Notice: Undefined offset: 3 in...
- image3-small.jpg
- image3-medium.jpg
- image3-large.jpg
- Notice: Undefined offset: 6 in...
---
expected
This is Adam
- image1-small.jpg
- image1-medium.jpg
- image1-large.jpg
- Adam
---
This is Peter
- image2-small.jpg
- image2-medium.jpg
- image2-large.jpg
- Peter
---
This is Susi
- image3-small.jpg
- image3-medium.jpg
- image3-large.jpg
- Susi
---
$imgsArrayand then ignore most of them and add what looks like the same extension in the loop?