我正在尝试显示存储在2个数组中的图像的元数据…
当图像没有名称时,我想显示“ no-name”。这是我现在显示这些的方式:
$imgs = array('img 1','img 2','img 3','img 4','img 5','img 6');
$imgNames = array('name 1','name 2','name 3',);
foreach($imgs as $files => $img)
{
echo 'Image: '.$img.' and Name: '.$imgNames[$files].'<br>';
};
我期望输出:
Image: img 1 and Name: name 1
Image: img 2 and Name: name 2
Image: img 3 and Name: name 3
Image: img 4 and Name: no-name
Image: img 5 and Name: no-name
Image: img 6 and Name: no-name
但实际输出是:
Image: img 1 and Name: name 1
Image: img 2 and Name: name 2
Image: img 3 and Name: name 3
Notice: Undefined offset: 3 in XX.php …
Image:img 4 and Name:
Notice: Undefined offset: 4 in XX.php …
Image:img 5 and Name:
Notice: Undefined offset: 5 in XX.php …
Image:img 6 and Name:
如何解决此问题以显示默认的“无名称”字符串?
潇湘沐
一只萌萌小番薯