Jump to content

Unexpected output in random code generation script


Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.