3v4l.org

run code in 500+ PHP versions simultaneously
<?php function formatStrings($strings, $positions) { $position = 0; foreach ($strings as $key => $str) { // do we need to move to a new position to display the next string? if ($positions[$key]['position'] > $position) { echo str_pad('', $positions[$key]['position'] - $position - 1); $position = $positions[$key]['position']; } // display the string echo str_pad($str, $positions[$key]['width']); $position += $positions[$key]['width'] - 1; } } $strings = array('ETL','E7954','20181123'); $positions = array(array('position' => 20, 'width' => 9), array('position' => 48, 'width' => 14), array('position' => 64, 'width' => 8)); echo " 1 2 3 4 5 6 7\n"; echo "12345678901234567890123456789012345678901234567890123456789012345678901234567890\n"; echo formatStrings($strings, $positions);

preferences:
56.04 ms | 1508 KiB | 5 Q