| px | top | add code | search | signup | login | help |
<?php
function padding(&$array, $character, $length = 0){
if(count($array) == 0) return;
$longest = 0;
for($i=0; $i<count($array); $i++){
if(strlen($array[$i]) > strlen($array[$longest])) $longest = $i;
}
if($length == 0) $length = strlen($array[$longest]);
for($i=0; $i<count($array); $i++){
$padding = $length - strlen($array[$i]);
for($j=0; $j<$padding; $j++){
$array[$i] .= $character;
}
}
}
?>
Example padding an array with spaces:
padding($yourarray, ' ');
Example padding an array to 50 characters with full stops:
padding($yourarray, '.', 50);
Comments or questions?
PX is running PHP 5.2.11
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.