scuff Posted December 28, 2008 Share Posted December 28, 2008 Please explain why this sometimes outputs nothing: <?php $morecharacters = "1234567890abcedefghijklmnopqrstuvwxyz"; echo $morecharacters[mt_rand(0, strlen($morecharacters))-1]; ?> Link to comment https://forums.phpfreaks.com/topic/138651-solved-bug-small-error/ Share on other sites More sharing options...
Mark Baker Posted December 28, 2008 Share Posted December 28, 2008 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]; Link to comment https://forums.phpfreaks.com/topic/138651-solved-bug-small-error/#findComment-724930 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.