我需要在for()语句中使用OR(||)运算符,但它不像预期的那样工作。使用for()来评估多个项目
我发送4个附件。两个是内嵌图像,另外两个是实际附件。
的问题是,它只能通过两个内置图片循环($结果[“相关”])
我认为我的解决方案很简单,但我只是没有看到它。
这里是我的代码:
# Check for attachments
if(isset($results['Related']) || isset($results['Attachments']))
{
if(isset($results['Related']))
{
$attachment_type = $results['Related'];
}
elseif(isset($results['Attachments']))
{
$attachment_type = $results['Attachments'];
}
for($i = 0; ($i < count($results['Attachments']) || $i < count($results['Related'])); $i++)
{
# Format file name (change spaces to underscore then remove anything that isn't a letter, number or underscore)
$filename = preg_replace('/[^0-9,a-z,\.,_]*/i', '', str_replace(' ', '_', $attachment_type[$i]['FileName']));
/* LOTS MORE CODE HERE */
}
}
编辑:我忘了告诉你了什么问题。
您遇到了什么问题?没有理由不能在你的陈述中使用'||'。不知道你的问题是否来自于在没有设置或没有设置的东西上运行count()。 – BAF
啊,我在发表评论之前没有看到您的编辑。 – BAF