abhishekdeveloper Posted May 27, 2012 Share Posted May 27, 2012 Dear All, Below is a program that generates a random password each time the page loads, I am getting an unexpected output as "Array" on running the script: <?php $character_set_array = array( ); $character_set_array[ ] = array( 'count' => 5, 'characters' => 'abcdefghijklmnopqrstuvwxyz' ); $character_set_array[ ] = array( 'count' => 1, 'characters' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ); $character_set_array[ ] = array( 'count' => 1, 'characters' => '0123456789' ); $character_set_array[ ] = array( 'count' => 1, 'characters' => '!@#$+-*&?:' ); $temp_array = array( ); foreach ( $character_set_array as $character_set ) { for ( $i = 0; $i < $character_set[ 'count' ]; $i++ ) { $temp_array[ ] = $character_set[ 'characters' ][ rand( 0, strlen( $character_set[ 'characters' ] ) - 1 ) ]; } } shuffle( $temp_array ); implode( '', $temp_array ); echo $temp_array; ?> I am expecting output in the below format: mczt0:Rm 2dwvJp!v wo9iVk@b c5xmx:xR a!Xwm5qk oyv!p8Sg Tiu8rb&w rmw&fa1I Kindly help me out by suggesting changes/modifications/errors. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/263200-unexpected-output-in-random-code-generation-script/ Share on other sites More sharing options...
trq Posted May 27, 2012 Share Posted May 27, 2012 You never save the value returned by implode to a variable. Quote Link to comment https://forums.phpfreaks.com/topic/263200-unexpected-output-in-random-code-generation-script/#findComment-1348929 Share on other sites More sharing options...
abhishekdeveloper Posted May 27, 2012 Author Share Posted May 27, 2012 Thanks thorpe, problem solved! Quote Link to comment https://forums.phpfreaks.com/topic/263200-unexpected-output-in-random-code-generation-script/#findComment-1348992 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.