PHP – Zero leading for numeric values

Using a recursive function:

/**
 * Zero leading for numeric values
 * 
 * @param $number
 * @param $length
 * @return mixed
 */
function zeroLead($number, $length = 1)
{
	return (strlen($number) >= $length) ? $number : zeroLead('0' . $number, $length);
}

Using str_pad() function:

/**
 * Zero leading for numeric values using str_pad() function
 *
 * @param $number
 * @param int $length
 * @return string
 */
function zeroPadLeft($number, $length = 1)
{
	$number = str_pad($number, $length, '0', STR_PAD_LEFT);
	
	return $number;
}

Using str_repeat() function:

/**
 * Zero leading for numeric values using str_repeat() function
 * 
 * @param $number
 * @param $length
 * @return string
 */
function zeroRepeatLeft($number, $length = 1)
{
	$diff = $length - strlen($number);
	if ($diff <= 0) {
		return $number;
	} else {
		return str_repeat('0', $diff) . $number;
	}
}