3v4l.org

run code in 300+ PHP versions simultaneously
<?php $value = '936656'; $length = (strlen($value) == 3) ? 3 : 2; echo str_pad($value, $length, '0', STR_PAD_LEFT);

preferences:
47.4 ms | 402 KiB | 5 Q