Jump to content

[SOLVED] Bug - Small error


scuff

Recommended Posts

Please explain why this sometimes outputs nothing:

Because $morecharacters is a string, but you're trying to treat it as though it were an array.

You're also potentially getting a negative entry value.

 

$morecharacters = "1234567890abcedefghijklmnopqrstuvwxyz";
$element = mt_rand(0, strlen($morecharacters)-1);
echo $morecharacters{$element};

 

$morecharacters = "1234567890abcedefghijklmnopqrstuvwxyz";
$morecharactersArray = str_split($morecharacters);
$element = mt_rand(0, strlen($morecharacters)-1);
echo $morecharactersArray[$element];

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.