PHP数组让我感到震惊

时间:2013-08-10 02:09:49

标签: php arrays


我有一些变量可以检索数据库中的一些数据,如下所示:

foreach ($row as $result) {
    if ($row[28] == '') {
        $string28 = '';
    }else if( $row[28] == 0){
        $string28 = '';
    } else{
        $string28 = '<div class="add_img"><h1>Connexion</h1><img src="images/'.$row[28].'.jpeg"></div>';
    }
}


foreach ($row as $result) {
    if ($row[30] == '') {
        $string30 = '';
    }else if($row[30] == 0){
        $string30 = '';
    } else{
        $string30 = '<div class="add_img"><h1>Fixation</h1><img src="images/'.$row[30].'.jpeg"></div>';
    }
}

foreach ($row as $result) {
    if ($row[31] == '') {
        $string31 = '';
    }else if($row[31] == 0){
        $string31 = '';
    } else{
        $string31 = '<div class="add_img"><h1>Schéma</h1><img src="images/'.$row[31].'.jpeg"></div>';
    }
}

这是节目结果代码:

<h1>Application</h1>
<div class="clear"></div>
<div class="add_div">
<?php
echo $string28;
echo $string29;
echo $string30;
echo $string31;
echo $string34;

?>

但我不能用php 编码这个表达式 首先我想将所有变量存储在一个数组中,然后说如果数组是空的这里我们讨论的是所有te变量是否为空然后回显espression 没有什么< / EM>

希望你能帮我一个人。
并且事先感谢你们所有人。

1 个答案:

答案 0 :(得分:2)

您的问题有点令人困惑,但要判断变量是否为空,只需使用empty()

if(empty($string28)) {
   // do something since it's empty
}

它也适用于数组......

$array = array();
if(empty($array)) {
   echo "Yep, it's empty!";
}