【发布时间】:2019-04-21 09:55:39
【问题描述】:
我正在尝试显示存储在 2 个数组中的图像元数据...
当图像没有名称时,我想显示“无名称”。以下是我现在的显示方式:
$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:
如何解决此问题以显示默认的“无名”字符串?
【问题讨论】:
-
感谢纠正@YakovL
-
不客气。查看您的其他问题,我建议您在制定这些问题上投入更多精力:这将帮助您获得(更多,更好)答案