What does this do?
Moderator: General Moderators
What does this do?
mt_rand(10,12)?ucfirst($str[$i]):strtolower($str[$i])
any other way,the above statement can be written?
any other way,the above statement can be written?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: What does this do?
what is the result of
mt_rand(0,1)?ucfirst($str[$i]):strtolower($str[$i]) ?
mt_rand(0,1)?ucfirst($str[$i]):strtolower($str[$i]) ?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: What does this do?
Code: Select all
$foo = mt_rand(0,1)?ucfirst($str[$i]):strtolower($str[$i])Code: Select all
if (mt_rand(0,1) ) { // false when 0, true when not 0
$foo = ucfirst($str[$i]);
} else {
$foo = strtolower($str[$i]);
}(#10850)
Re: What does this do?
thanks....
if (mt_rand(0,1) ) { // false when 0, true when not 0
$foo = ucfirst($str[$i]);
} else {
$foo = strtolower($str[$i]);
}
does that indicate if (mt_rand(0,1)) means the following if (mt_rand(0,1)==0)?
instead we could give
$str= mt_rand(0,1)
if ($str==0 ) { // false when 0, true when not 0
$foo = ucfirst($str[$i]);
} else {
$foo = strtolower($str[$i]);
}
if (mt_rand(0,1) ) { // false when 0, true when not 0
$foo = ucfirst($str[$i]);
} else {
$foo = strtolower($str[$i]);
}
does that indicate if (mt_rand(0,1)) means the following if (mt_rand(0,1)==0)?
instead we could give
$str= mt_rand(0,1)
if ($str==0 ) { // false when 0, true when not 0
$foo = ucfirst($str[$i]);
} else {
$foo = strtolower($str[$i]);
}
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: What does this do?
No.treesa wrote:does that indicate if (mt_rand(0,1)) means the following if (mt_rand(0,1)==0)?
Code: Select all
if (mt_rand(0,1)) {
// is the same as
if (mt_rand(0,1) != 0) {You are using $str for two different things there. The value returned from mt_rand() will be 0 or 1. No reason to convert those to upper or lower case!treesa wrote:instead we could give
$str= mt_rand(0,1)
if ($str==0 ) { // false when 0, true when not 0
$foo = ucfirst($str[$i]);
} else {
$foo = strtolower($str[$i]);
}
(#10850)
Re: What does this do?
sorry,i meant,
instead we could give
$str1= mt_rand(0,1)
if ($str1==0 ) { // false when 0, true when not 0
$foo = ucfirst($str[$i]);
} else {
$foo = strtolower($str[$i]);
}
instead we could give
$str1= mt_rand(0,1)
if ($str1==0 ) { // false when 0, true when not 0
$foo = ucfirst($str[$i]);
} else {
$foo = strtolower($str[$i]);
}
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: What does this do?
Yes, $str1 will hold the value from mt_rand(0,1) so it will contain 0 or 1.
(#10850)