Dynamic two-column list, "Vertical Wrap" I have created a very simple script that will create two columns which are populated by an array. It works, but I am certain that the way that I have gone about it is not the best way. I have been searching for simple, sample scripts which would aide me in understanding how to best approach this, but all of them have been too specific to their application.

This is what I have made:

$assets = array('Bag', 'Charger', 'Power Cable', 'Video Cable', 
    'Mouse', 'Keyboard', 'Test', 'Test 2', 'Test 3');
$assets_count = count($assets);

$halfway_raw = $assets_count / 2;
$halfway = round($halfway_raw, 0) - 1;

echo '&lt;ul class="col-1"&gt;';

for($i = 0; $i &lt; $assets_count; $i++) {
    if($i == $halfway) {
        echo '&lt;li&gt;' . $assets[$i] . '&lt;/li&gt;';
        echo '&lt;/ul&gt;';
        echo '&lt;ul class="col-2"&gt;';
    } else {
        echo '&lt;li&gt;' . $assets[$i] . '&lt;/li&gt;';
    }
}

echo '&lt;/ul&gt;';


I'm looking for something that scales easily and is obviously as small as possible, which I don't think my script is.
Well, this is more concise, and it should be easy enough to scale:

&lt;?php
$assets = array('Bag', 'Charger', 'Power Cable', 'Video Cable', 'Mouse', 'Keyboard', 'Test', 'Test 2', 'Test 3');

$half   = ceil(count($assets)/2);

$columns = array(
  array_slice($assets, 0, $half), // first half
  array_slice($assets, $half)     // second half
);

foreach( $columns as $index =&gt; $column ) {
  $index += 1;
  echo "&lt;ul class=\"col-$index\"&gt;&lt;li&gt;" . implode("&lt;/li&gt;&lt;li&gt;", $column) . "&lt;/li&gt;&lt;/ul&gt;";
}
?&gt;


Basically, it's using more built-in PHP functions and constructs (array_slice, implode, foreach) but is functionally identical to the original.