Notice: Uninitialized string offset in PHP -


Hello, I have this function and it returns a notice:

Notice: Unscrupited string offsets:

function generator and $ ($ length) {$ string = ''; $ Letters = "0123456789abcdef"; ($ P = 0; $ p & lt; $ length; $ p ++) {$ string = $ Letters [mt_rand (0, strlen ($ letters)); } Return $ string; }

The affected line is:

  $ string. = $ Letters [mt_rand (0, strlen ($ letters)];   

I have tried to do with braces and it does not work. If someone can tell some suggestion, then I appreciate it. Thank you.

You can sometimes sometimes overwrite due to $ letter strlen ($ Character) , which should be strlen ($ letters) - 1 . Your random series should start with zero, and you have to end with a zero length if the $ character is 10, then the last zero-based array index < Em> nine , and it keeps up your upper limit for random selection.

  $ string = ''; $ Letters = "0123456789abcdef"; ($ P = 0; $ p & lt; $ length; $ p ++) {$ string = $ Characters [mt_rand (0, strlen ($ letters) - 1)]; }   

Because you are randomly selected, you do not always get the information - it only happens when mt_rand () returns its maximum value at any point In your loop

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -