View Full Version : PHP Help
iUnknown
31-08-2008, 07:56 PM
Hi,
Please tell me what you think will happen if I run:
function sesid()
{
for($i=0; $i++; $i<8)
{
$num = rand(1,9);
$sesid .= $num;
}
}
sesid();
I know what SHOULD happen but I don't think it's working.
Thanks.
Hi,
Please tell me what you think will happen if I run:
function sesid()
{
for($i=0; $i++; $i<8)
{
$num = rand(1,9);
$sesid .= $num;
}
}
sesid();
I know what SHOULD happen but I don't think it's working.
Thanks.
Cant see anything wrong with it. I ran it and i get a number between 1 and 9. so it works :)
Invent
31-08-2008, 08:01 PM
function sesid( )
{
for( $i = 0; $i < 8; $i++ )
{
$num = rand( 1,9 );
$sesid .= $num;
}
return $sesid;
}
$id = sesid( );
iUnknown
31-08-2008, 08:41 PM
Cant see anything wrong with it. I ran it and i get a number between 1 and 9. so it works :)
You're supposed to get an 8 digit number haha.
function sesid( )
{
for( $i = 0; $i < 8; $i++ )
{
$num = rand( 1,9 );
$sesid .= $num;
}
return $sesid;
}
$id = sesid( );
Works like a charm, thanks very much. +rep
Decode
31-08-2008, 08:45 PM
If you're trying to get an eight digit number why not do-
rand( "10000000", "99999999" );
Invent
31-08-2008, 09:09 PM
If you're trying to get an eight digit number why not do-
rand( "10000000", "99999999" );
That'd be the better method.
iUnknown
31-08-2008, 09:17 PM
function sesid( )
{
for( $i = 0; $i < 8; $i++ )
{
$num = rand( 1,9 );
$sesid .= $num;
}
return $sesid;
}
$id = sesid( );
Ah well as long as it works it's fine. Like the wires at the back of my computer, messy, but works great ;)
Hypertext
31-08-2008, 10:45 PM
For loops are a lot slower than Toms method. Your logic is... interesting.
iUnknown
31-08-2008, 10:50 PM
Haha fine, I'll test it and use it.
$id = rand( "10000000", "99999999" );
$sesid = $id;
works like a charm :) would +rep Tom but gotta spread.
Agnostic Bear
01-09-2008, 05:54 AM
If you're trying to get an eight digit number why not do-
rand( "10000000", "99999999" );
Why are you using strings on a number randomiser?
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.