将值显示为数组中的单个值

时间:2016-10-20 07:04:44

标签: mysql arrays codeigniter

当我使用我的代码时

<?php 
 $n=1; $j=1
   foreach($result as $row){
     $i=1;
     $occupied= '';
        foreach ($b as $res) {
             if($j==$i)                  
               {
                   $occupied=$res;
                }
           $i++;
         } 
    $j++;
  ?>
 <td>
 <?php if($occupied){
      $tagsLinks = implode(',', $occupied);
             echo '<a class="label label-success" href="view_room_occupied/'.$tagsLinks.'">'.$tagsLinks.'</a>';
                    }
                else
                    {
                       echo 'Nil';
                    }  ?>

                    </td>

输出结果就像一个数组,但我希望得到的每个值应该与数组分开

存储在$ occupied中的值就像这样

C:\wamp64\www\hosteliam2\application\views\admin\view_status.php:93:
array (size=2)
0 => string '1A' (length=2)
1 => string '1B' (length=2)

C:\wamp64\www\hosteliam2\application\views\admin\view_status.php:93:
array (size=2)
0 => string '2A' (length=2)
1 => string '2B' (length=2)

1 个答案:

答案 0 :(得分:0)

这是我改变的代码

<?php 
 $n=1; $j=1
   foreach($result as $row){
    $i=1;
    $occupied= '';
         foreach ($b as $res) {
             if($j==$i) {
                             $occupied=$res;
                             $Array = array();
                             foreach($occupied as $res1){
                             $tagName = trim($res1);
                             $Array[]= '<a class="label label-success" href="view_room_occupied/'.$tagName.'">'.$tagName.'</a>';


                             }
                         }
               $i++;
            } 
            $j++;
         ?>
 <td>
 <?php if($occupied){
      $tagsLinks = implode(',', $Array);
       echo $tagsLinks;
        }
        else{
           echo 'Nil';
             } ?>

  </td>