doulanli6146 2015-11-06 19:21
浏览 148
已采纳

如何填充数组中的字符串?

I'm trying to fill in a string in an array value that has a empty '' do I need to use isset or empty to check it first?

Here is my code

echo table();

function table() {
    $a = array  ('0' => array('Jan de Boer', '213','440'),
                 '1' => array('Gerda Severin','214','442'),
                 '2' => array('Jean Dubois','215',''),
                 '3' => array('Peter Geringh','221','449'),
                 '4' => array('ricardo','666','666'));

    echo "<table border='6px'>
    <tr><th colspan='3'>Alle werknemers</th></tr>
    <tr><th>Naam</th>
    <th>kamer</th>
    <th >Toestelnummer</th></tr>";

    for ($x=0;$x<5;$x++){
        echo "<tr>";
        for($y=0;$y<3;$y++){
            echo "<td>",$a[$x][$y].'</td>';
        }
        echo "</tr>";
    }
    echo "</table>";
}

It needs to fill in the blank '' like a string unknown.

  • 写回答

2条回答 默认 最新

  • dongxiangchan0743 2015-11-06 19:25
    关注

    Perform a check if the string is blank and replace with a value, in my example 'UNKNOWN'

        echo table();
    function table()
    
    {    
    $a = array  ('0' => array('Jan de Boer', '213','440'),
                 '1' => array('Gerda Severin','214','442'),
                 '2' => array('Jean Dubois','215',''),
                 '3' => array('Peter Geringh','221','449'),
                 '4' => array('ricardo','666','666'));
    
    echo "<table border='6px'>
    <tr><th colspan='3'>Alle werknemers</th></tr>
    <tr><th>Naam</th>
    <th>kamer</th>
    <th >Toestelnummer</th></tr>";
    
        for ($x=0;$x<5;$x++){
        echo "<tr>";
        for($y=0;$y<3;$y++){
        if($a[$x][$y] == "") $a[$x][$y] = 'UNKNOWN';
            echo "<td>",$a[$x][$y].'</td>';
        }
        echo "</tr>";
    }
    
    echo "</table>";
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?