Skip to content
Advertisement

PHP HTML foreach loop

How would I be able to make a table from php using html with a foreach loop? My goal is to have a table with href tags for each of the sites. It’s just that I’m a newbie to php

<?php
 $baseConf = ['site' => [abc.com],[abc.org]];
?>
<!DOCTYPE html>
<html>
    <head>
        <title>Default Page</title>
    </head>
    <body>
        <table>
            <!--<a href="<?php //$site; ?>"><?php //$site; ?></a>-->
            <?php
                foreach($site as $value ) {
                    printf $value;
                  }
             ?>
         </table>
       </body>
</html>

Advertisement

Answer

I have fixed my code a bit and this is what worked out:

$baseConf = array(
        'site' => array("abc.com","abc.org"),
                );
?>
<!DOCTYPE html>
<html>
        <head>
         <title>Default Page</title>
        </head>
        <body>
          <!--<a href="<?php //$site; ?>"><?php //$site; ?></a>-->
            <?php
              foreach ($baseConf as $value) {
              //echo "$valuen"; 
              print_r($value);
              }
              ?>
        </body>
</html>
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement