LeftPad in PHP

Press + to interact
<?php
function leftPad($inputStr, $paddingLength, $ch = ".") {
if(strlen($ch) !== 1) {
return "error";
}
$paddingLength = $paddingLength - strlen($inputStr);
$strCh = '';
for ($i = 0; $i < $paddingLength; ++$i) {
$strCh = $strCh.$ch;
}
return $strCh.$inputStr;
}
echo leftPad('1', 1);
echo leftPad('2', 2);
echo leftPad('3', 3);
echo leftPad('4', 4);
echo leftPad('5', 5);
echo leftPad('hello', 7);
echo leftPad("foo", 6);
echo leftPad("foo", 3);
echo leftPad("foobar", 3);
echo leftPad("foo", 6, "?");
?>