# placing array results into html tables

**URL:** <https://www.phphelp.com/t/placing-array-results-into-html-tables/18925>\
**Category:** General PHP Help\
**Created:** [November 16, 2012, 3:25pm UTC](https://www.phphelp.com/t/placing-array-results-into-html-tables/18925 "2012-11-16T15:25:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![runman](https://www.phphelp.com/user_avatar/www.phphelp.com/runman/32/706_2.png) [@runman](https://www.phphelp.com/u/runman)\
**Post date:** [November 16, 2012, 3:25pm UTC](https://www.phphelp.com/t/placing-array-results-into-html-tables/18925/1 "2012-11-16T15:25:01Z")

</div>

Hi,

I am currently working on creating a code that grabs information from an array and places them into an html table. The only extra part is that I also have to separate the information within the array where there are colons and put them into separate table columns. I was able to create the code below, but just cant seem to get the tables to align or fit in the correct places. Any help or suggestion is really appreciated and thank you guys in advance.

[php]\<?php  
$nocolon = $colon = “”;

$feat = array(  
“feat1” =\> “nocolon1:colog1”,  
“feat2” =\> “nocolon2:colog2”,  
“feat3” =\> “nocolon3:colog3”,  
“feat4” =\> “nocolon4:colog4”,  
);

foreach ($feat as $val){  
$nocolon .= strstr($val, ‘:’, true);  
$nocolon = $nocolon . “  
”;

```
$colon .= strstr($val, ':', false);
$colon = $colon . "<br />";

```

}

$nocolon = “  
$nocolon”;  
$nocolon = str\_replace("  
", “

”, $nocolon);  
$colon = str\_replace("  
", “ ”, $colon);

echo \<\<\<\_END

 $nocolon $colon

\_END; ?\>[/php]

---

<div class="post-metadata">

**Author:** ![runman](https://www.phphelp.com/user_avatar/www.phphelp.com/runman/32/706_2.png) [@runman](https://www.phphelp.com/u/runman)\
**Post date:** [November 17, 2012, 3:28pm UTC](https://www.phphelp.com/t/placing-array-results-into-html-tables/18925/2 "2012-11-17T15:28:49Z")

</div>

Got help and figured it out. Just in case anyone is looking for something similar here is what I got.

[php]

\<?php $feat = array( "feat1" =\> "nocolon1:colog1", "feat2" =\> "nocolon2:colog2", "feat3" =\> "nocolon3:colog3", "feat4" =\> "nocolon4:colog4", ); $tableData = ''; foreach($feat as $name =\> $dataAry) { $tableData .= "\n"; $tableData .= "{$name}\n"; foreach(explode(':', $dataAry) as $data) { $tableData .= "{$data}\n"; } $tableData .= "\n"; } ?\> \<?php echo $tableData; ?\>

[/php]
