【发布时间】:2013-08-10 03:16:54
【问题描述】:
我有这个代码:
foreach ($row as $result) {
if (empty($row[28])) {
$string28 = '';
} else {
$string28 = '<div class="add_img">
<h1>Connexion</h1>
<img src="images/' . $row[28] . '.jpeg">
</div>';
}
}
foreach ($row as $result) {
if (empty($row[30])) {
$string30 = '';
} else {
$string30 = '<div class="add_img">
<h1>Fixation</h1>
<img src="images/' . $row[30] . '.jpeg">
</div>';
}
}
foreach ($row as $result) {
if (empty($row[31])) {
$string31 = '';
} else {
$string31 = '<div class="add_img">
<h1>Schéma</h1>
<img src="images/' . $row[31] . '.jpeg">
</div>';
}
}
$applications = array($string28, $string30, $string31);
if (empty($applications)) {
$vide = "<h1>Pas D'Application Pour Ce Produit</h1>";
}
我在这里想说的是:如果所有变量都是空的,那么给我看这个:
Pas D'Application Pour Ce Produit
(翻译:该产品无申请)
但是当我使用 print_r 函数时,它告诉我该数组没有要处理的数据。
我需要帮助。
感谢所有高级人员
【问题讨论】:
-
你在哪里使用 print_r。空函数检查数组是否为空,而不是每个单独的变量
-
那么如何将它用于所有变量?
-
遍历它们并单独检查它们是否为空
-
像你一样循环遍历数组,并使用 empty() 或 isset() 检查数组值。 isset() 实际上会告诉你这样的变量是否已经初始化并且不为空。