note 105990 added to function.base-convert
| From: | bpds at osu1 dot php dot net | Date: | Fri, 30 Sep 2011 12:47:32 +0000 |
| Subject: | note 105990 added to function.base-convert | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-183541@lists.php.net to get a copy of this message | ||
A simple function to convert an int to any base.
function intToAlphaBaseN($n,$baseArray) {
$l=count($baseArray);
$s = '';
for ($i = 1; $n >= 0 && $i < 10; $i++) {
$s = $baseArray[($n % pow($l, $i) / pow($l, $i - 1))].$s;
$n -= pow($l, $i);
}
return $s;
}
$alpha=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');
$r=rand(0, 99999999999);
echo(intToAlphaBaseN($r,$alpha));
----
Server IP: 69.147.83.197
Probable Submitter: 193.252.28.244
----
Manual Page -- http://www.php.net/manual/en/function.base-convert.php
Edit -- https://master.php.net/note/edit/105990
Del: integrated -- https://master.php.net/note/delete/105990/integrated
Del: useless -- https://master.php.net/note/delete/105990/useless
Del: bad code -- https://master.php.net/note/delete/105990/bad+code
Del: spam -- https://master.php.net/note/delete/105990/spam
Del: non-english -- https://master.php.net/note/delete/105990/non-english
Del: in docs -- https://master.php.net/note/delete/105990/in+docs
Del: other reasons-- https://master.php.net/note/delete/105990
Reject -- https://master.php.net/note/reject/105990
Search -- https://master.php.net/manage/user-notes.php