我有以下 PHP 代码:
<?php
//code above
$pic_1 = $afil['image_1'];
$pic_2 = $afil['image_2'];
$pic_3 = $afil['image_3'];
$pic_4 = $afil['image_4'];
$pic_5 = $afil['image_5'];
$pic_6 = $afil['image_6'];
$pic_7= $afil['image_7'];
$pic_8 = $afil['image_8'];
$pic_9 = $afil['image_9'];
$pic_10 = $afil['image_10'];
if ($pic_1 = "")
{
$pic_1 = //defaultpic - to be defined, same as below
}
if ($pic_2 = "")
{
$pic_2 = //defaultpic
}
?>
与其对每张图片重复这些“if”语句(直到 $pic 10),我只是想知道是否有人可以指出一种更优雅、更有效的方法。我对php很陌生,这是我遇到的新情况。提前非常感谢。