AL8 Forum
   登錄註冊幫助


標題: 隨機一問 [ array_rand ]
 烈魂
 0105950
Rank: 3Rank: 3Rank: 3
點擊查看 烈魂 的詳細資料

頭銜: Conqueror

帖子: 228

精華: 0

積分: 2580 點

現金: 70 元

存款: 0 元

閱讀權限: 20

註冊: 2008-8-2

來自: HK

狀態: 離線
 
發表於 2008-9-24 20:40  資料  個人空間  主頁 短消息  加為好友  添加 烈魂 為MSN好友 通過MSN和 烈魂 交談
隨機一問 [ array_rand ]

請問
$randwords = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","1","2","3","4","5","6","7","8","9","0");
$key = array_rand($randwords);
$randid = $randwords[$key];
這句語法
如何可以改為每次隨機5個不同的數字+英文字




 AL8 Forum © All rights reserved.
頂部
 ntf
 0043014
Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

頭銜: Moderator

自述: ntf

帖子: 3712

精華: 0

積分: 6393 點

現金: 0 元

存款: 38423 元

閱讀權限: 100

註冊: 2006-4-7

狀態: 離線
 
發表於 2008-9-24 20:53  資料  個人空間  短消息  加為好友 




 AL8 Forum © All rights reserved.
頂部
 烈魂
 0105950
Rank: 3Rank: 3Rank: 3
點擊查看 烈魂 的詳細資料

頭銜: Conqueror

帖子: 228

精華: 0

積分: 2580 點

現金: 70 元

存款: 0 元

閱讀權限: 20

註冊: 2008-8-2

來自: HK

狀態: 離線
 
發表於 2008-9-24 21:18  資料  個人空間  主頁 短消息  加為好友  添加 烈魂 為MSN好友 通過MSN和 烈魂 交談
QUOTE:
原帖由 ntf 於 2008-9-24 20:53 發表
$keys=array_rand($randwords,5);
http://hk.php.net/manual/en/function.array-rand.php

我想配合SQL使用
<input type="hidden" name="randname" value="<?=$randid?>" />
但唔知點解會出錯
有冇另一個方法?




 AL8 Forum © All rights reserved.
頂部
 Puff
 0040634
Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7
點擊查看 Puff 的詳細資料

頭銜: Moderator

帖子: 495

精華: 0

積分: 4679 點

現金: 244 元

存款: 0 元

閱讀權限: 100

註冊: 2006-2-26

狀態: 離線
 
發表於 2008-9-25 00:41  資料  個人空間  短消息  加為好友 
function random($length) {
        $words = "abcdefghijklmnopqrstuvwxyz1234567890";
        $totalwords = strlen($words) - 1;
        $str = '';
        for( $i = 0; $i < $length; $i++ ) {
                $str .= $words[rand(0, $totalwords)];
        }
        return $str;
}
$random_str = random(5);




 AL8 Forum © All rights reserved.
頂部
 烈魂
 0105950
Rank: 3Rank: 3Rank: 3
點擊查看 烈魂 的詳細資料

頭銜: Conqueror

帖子: 228

精華: 0

積分: 2580 點

現金: 70 元

存款: 0 元

閱讀權限: 20

註冊: 2008-8-2

來自: HK

狀態: 離線
 
發表於 2008-9-26 18:30  資料  個人空間  主頁 短消息  加為好友  添加 烈魂 為MSN好友 通過MSN和 烈魂 交談
QUOTE:
原帖由 puff 於 2008-9-25 00:41 發表
function random($length) {
        $words = "abcdefghijklmnopqrstuvwxyz1234567890";
        $totalwords = strlen($words) - 1;
        $str = '';
        for( $i = 0; $i < $length; $i++ ) {
                $str .= $words;
        }
        retur ...


謝謝..問題已解決




 AL8 Forum © All rights reserved.
頂部

聯繫我們 - AL8 Forum - 網頁空間由 I-SERVICES 提供 - Archiver - WAP
清除 Cookies, 當前時區 GMT+8, 現在時間是 2008-12-3 11:22
Processed in 0.050038 second(s), 7 queries , Gzip enabled
Powered by Discuz! 5.5.0  © 2001-2007 Comsenz Inc.