테스트 사이트 - 개발 중인 베타 버전입니다

초보의 질문입니다. 숫자 정렬

<?
for($i=1; $i<46; $i++) {
$i = sprintf("%02d",$i);
$lotto[$i] = $i;
}
shuffle($lotto);
echo "<font color=pink></font>&nbsp;&nbsp;";
echo $lotto[0]."&nbsp;<font color=silver> </font> ".$lotto[1]."&nbsp;<font color=silver> </font> ".$lotto[2]."&nbsp;<font color=silver> </font> ".$lotto[3]."&nbsp;<font color=silver> </font> ".$lotto[4]."&nbsp;<font color=silver> </font> ".$lotto[5];
?>


로또번호 자동생성 소스인데요. 숫자가 정렬이 되게 하려합니다.

42 25 06 27 45 01 -> 01 06 25 27 42 45 이런식으로요. 부탁드립니다. ^^<div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]</div>

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

댓글 4개

<?
for($i=1; $i<46; $i++) {
$i = sprintf("%02d",$i);
$lotto[$i] = $i;
}
$lotto = array_rand($lotto,6);
echo "<font color=pink></font>&nbsp;&nbsp;";
echo $lotto[0]."&nbsp;<font color=silver> </font> ".$lotto[1]."&nbsp;<font color=silver> </font> ".$lotto[2]."&nbsp;<font color=silver> </font> ".$lotto[3]."&nbsp;<font color=silver> </font> ".$lotto[4]."&nbsp;<font color=silver> </font> ".$lotto[5];
?>
사하님 너무 감사드립니다.

그런데 이상하게 새로고침하면 또 정렬이 난되는듯하네요. ㅡ.ㅡ

너무 감사드립니다.

추가로 혹시

숫자 생성시 1~9는 앞에 0을 붙혀서 출력하려면 어떻게 해야하는지요?

<?
$arr = range(1,45);
shuffle($arr);
$arr_out = array_slice($arr,0,6);
sort($arr_out);
echo implode(" ",$arr_out);
?>

위 소스를 출력하면 1,2,11,13,15,16 이렇게 단번호에는 0이 안붙네요. ^^

즐거운 하루 되세요.
<?
$arr = range(1,45);
shuffle($arr);
$arr_out = array_slice($arr,0,6);
sort($arr_out);
foreach($arr_out as $arr_str)
{
echo sprintf("%02d",$arr_str)." ";
}
?>
감사합니다. 완벽하게 해결됬습니다.
사하님 정말 감사합니다. ^^

게시글 목록

번호 제목
1222
1219
1217
1214
1209
1207
1204
1201
1200
1199
1197
1192
1191
1190
1188
1187
1186
1185
1181
1180
1178
1172
1168
1167
1164
1159
1158
1156
1155
1146