如何从数组中获取多个值作为行格式

时间:2017-04-04 06:49:13

标签: php html arrays codeigniter

如果我们打印"我将从此数组中获取值的print_r($ totalteachersget);死; ?>现在我们得到这个下面的数组现在我希望在html中逐行格式,我的HTML代码也在吹 - 请修复我的HTML代码。

--------------------------------数组结果------------- --------------------

Array
(
    [0] => Array
        (
            [totalteachers] => Array
                (
                    [0] => stdClass Object
                        (
                            [teacher_id] => 1
                            [teacher_name] => Amit Rathore
                            [mobile_number] => 99999999
                            [email] => amitrathore48@gmail.com
                            [password] => e6e061838856bf47e1de730719fb2609
                            [gender] => male
                            [address] => nothing address
                            [rand_number] => eFhohRkL
                            [status] => 1
                            [created_at] => 2017-01-09 02:24:54
                            [logout_time] => 2017-01-27
                        )

                )

        )

    [1] => Array
        (
            [totalteachers] => Array
                (
                    [0] => stdClass Object
                        (
                            [teacher_id] => 49
                            [teacher_name] => thomas joy
                            [mobile_number] => 
                            [email] => davidthomasmobapps@gmail.com
                            [password] => 8a6d4494109584e7d36ed19b2dd3cb16
                            [gender] => 
                            [address] => 
                            [rand_number] => jgqf0RTG
                            [status] => 1
                            [created_at] => 2017-04-01 05:41:50
                            [logout_time] => 
                        )

                )

        )

)

------------------------------------- HTML Code -------- -------------------------

    <tbody>
    <?php if(!empty($totalteachersget)) {
        $i =1;
         foreach($totalteachersget as $teacherslist=>$values) { 
            foreach($totalteachers as $secondvalues) {                   
          $teacher_id = base64_encode(base64_encode(base64_encode($secondvalues->teacher_id)));
         ?> 
            <tr class="<?php  // echo $bgcolor; ?>">
                <td class="col-chk"><!--<input type="checkbox">--></td>
                <td class="col-first"><?php echo $secondvalues->teacher_name;  ?></td>
                <td class="col-third"><?php echo $secondvalues->mobile_number;  ?></td>
                <td class="col-second"><?php echo $secondvalues->email;  ?></td>
                <td class="col-second"><?php if($secondvalues->status == 0){ echo "Not confirmed"; } else { echo "Confirmed"; } ?></td>

            </tr>
         <?php $i++;  } } }else{ ?>
            <tr><td class="col-chk" colspan="10">No records found </td></tr>
        <?php  } ?>
        </tbody>

2 个答案:

答案 0 :(得分:0)

你的循环错了。试试这样并保留html部分:

foreach ($totalteachersget as $values) {
    foreach ($values['totalteachers'] as $teacher) {
         var_dump($teacher->teacher_name);
    }
}

答案 1 :(得分:0)

HTML code:

<?php
if(!empty($totalteachersget)) {
    foreach($totalteachersget as $offset => $totalteachers) { 
        foreach($totalteachers as $offset1 => $secondvalues) {                   
            foreach($secondvalues as $offset2 => $thirdvalues) {                   
                $teacher_id = base64_encode(base64_encode(base64_encode($thirdvalues->teacher_id)));
?> 
                <tr class="<?php  // echo $bgcolor; ?>">
                    <td class="col-chk"><!--<input type="checkbox">--></td>
                    <td class="col-first"><?php echo $thirdvalues->teacher_name;  ?></td>
                    <td class="col-third"><?php echo $thirdvalues->mobile_number;  ?></td>
                    <td class="col-second"><?php echo $thirdvalues->email;  ?></td>
                    <td class="col-second"><?php if($thirdvalues->status == 0){ echo "Not confirmed"; } else { echo "Confirmed"; } ?></td>

                </tr>
<?php 
            }
        } 
    } 
} else { ?>
    <tr><td class="col-chk" colspan="10">No records found </td></tr>
<?php  } ?>
</tbody>