0
Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [code] => ID 6401
                    [name] => Joseph

                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [code] => ID 6597
                    [name] => Peter
                )

        )

I Want print HTML Table like :

Code | Name

ID 6401 | Joseph
ID 6597 | Peter

Total : 2 Person

1

2 Answers 2

2

Use this one :

<table>
    <thead>
        <tr>
            <th>Code</th><th>Name</th>
        </tr>
    </thead>
    <tbody>
<?php
    foreach($users as $u){
        echo "<tr><td>". $u[0]['code'] ."</td><td>". $u[0]['name'] ."</td></tr>";
    };
    echo "<tr><td>Total :</td><td>".count($users)."</td></tr>";
?>
    </tbody>
</table>
Sign up to request clarification or add additional context in comments.

2 Comments

I have changed the index name as $u[0]['name'] chk revision
@devpro , ooopss i missed that. Thanks
0

Try by foreach and assign operator += will be help.

<?php
$user = array(
array(
    array(
    "code" => "ID 6401",
    "name" => "Joseph"
    )
),
array(
      array(
    "code" => "ID 6597",
    "name" => "Peter"
    )
));

 ?>
<table>
<thead><th>Code</th><th>Name</th></thead>
<tbody>
<?php 
$count = 0;
foreach ($user as $v){
  echo "<tr><td>".$v[0]['code']."</td><td>".$v[0]['name']."</td></tr>";
  $count += 1;  
}
  echo "<tr><td>Total:</td><td>".$count."</td></tr>";
?>
</tbody>

3 Comments

This is not actually an answer to the question because you have changed the shape of the array and the questioner may not be able to do that or may not want to do that. I admit your array is much more sensible, but its not as per the question
<?php $user = array( array( "code" => "ID 6401", "name" => "Joseph" ), array( "code" => "ID 6597", "name" => "Peter" ) ); ?> <table> <thead><th>Code</th><th>Name</th></thead> <tbody> <?php $count = 0; foreach ($user as $v){ echo "<tr><td>".$v['code']."</td><td>".$v['name']."</td></tr>"; $count += 1; } echo "<tr><td>Total:</td><td>".$count."</td></tr>"; ?> </tbody> it's work before update
I've changed it as your question array type !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.