- array_map: documentation ( source)
- explode: documentation ( source)
<?php
$input = "hello:20,test:40,abc:25";
function transform_input($input) {
return array_map(function ($value) {
list($title, $length) = explode(':', $value);
return [
'title' => $title,
'length' => $length
];
}, explode(',', $input));
}
$array = transform_input($input);
for($i=0; $i < count($array); $i++) { ?>
<th><?=$array[$i]["length"]?></th>
<th><?=$array[$i]["title"]?></th>
<?php } ?>