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]; ?> Quote Link to comment 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]; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.