1

I do not know how to create a table for three arrays using PHP with a foreach loop.

Code as follows:

$a = array ("Rama", "Seetha", "Kannan", "Shiva");
$b = array ("12", "10", "15", "17");
$c = array ("11", "b1", "d2", "10");

Expected output as follows:

Sno Name    Age Id
1   Rama    12  11
2   Seetha  10  b1
3   Kannan  15  d2
4   Shiva   17  10

1 Answer 1

1

$a = array ("Rama", "Seetha", "Kannan", "Shiva");
$b = array ("12", "10", "15", "17");
$c = array ("11", "b1", "d2", "10");

$count = count($a);

?>
<table>
    <thead>
        <tr>
            <th>Id</th>
            <th>Name</th>
            <th>Age</th>
            <th>Sno</th>
        </tr>
    </thead>
    <tbody> 
    <?php
        $j = 1;
        for ($i=0; $i < $count ; $i++) 
        { 
            $name = $a[$i];
            $age = $b[$i];
            $id = $c[$i];

            ?>
            <tr>
                <td><?php echo $j ?></td>
                <td><?php echo $name ?></td>
                <td><?php echo $age ?></td>
                <td><?php echo $id ?></td>
            </tr>
            <?php
            $j++;
        }
    ?>
    </tbody>
</table>
Sign up to request clarification or add additional context in comments.

4 Comments

sorry boss, Actually I was asking help to create a html report from these arrays using php with foreach loop.
@Balrajswamy check now.
thanks a lot for your great help and effort. Now I learned from you that how to handle it.
Happy to help :)

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.