게시물 번호 앞에 0 붙이고 싶어요
본문
<?php echo $list[$i]['num'];?> 이거를 쓰면
1 2 3 4 5... 이렇게 나오는데
01 02 03 이렇게 나오고 싶은데 어떻게 해야할까요?
10이상은 0이 빠지면 10 11 12 이렇게 나오게 하고 싶습니다
답변 4
echo sprintf('%02d', $list[$i]['num']);
https://stackoverflow.com/questions/1699958/formatting-a-number-with-leading-zeros-in-php
sprintf를 사용하면 됩니다.
sprintf('%02d', $list[$i]['num']) 로 해보세요...
echo ( intval($list[$i]['num']) < 10 ) ? '0'.$list[$i]['num']:'';
답변을 작성하시기 전에 로그인 해주세요.