Revision: 30397
Updated Code
at September 4, 2010 09:22 by DADU
Updated Code
/* EXAMPLE print_r(add_leading_zeros(range(1,100))); */ function add_leading_zeros($array) { foreach($array as $key=>$value) $array[$key] = str_pad($value,strlen(max($array)),'0',STR_PAD_LEFT); return $array; }
Revision: 30396
Updated Code
at August 13, 2010 05:31 by DADU
Updated Code
/* EXAMPLE print_r(addleadingzeros(range(1,100))); */ function addleadingzeros($array) { foreach($array as $key=>$value) $array[$key] = str_pad($value,strlen(max($array)),'0',STR_PAD_LEFT); return $array; }
Revision: 30395
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at August 13, 2010 05:29 by DADU
Initial Code
/* EXAMPLE print_r(addleadingzeros(range(1,100))); */ function addleadingzeros($array) { foreach($array as $key=>$value) $array[$key] = str_pad($value,strlen(max($array)),'0',STR_PAD_LEFT); return $array; }
Initial URL
Initial Description
This PHP code snippet checks each integer in an array. If necessary, one or more leading zeros are added to an integer. Note that each integer becomes a string.
Initial Title
add leading zeros
Initial Tags
list, array
Initial Language
PHP