3v4l.org

run code in 300+ PHP versions simultaneously
<?php mt_srand( 1234 ); // Arrange $input = []; for ($i = 0; $i < 10; $i++ ) { $input[] = wfRandomString( 5 ); } // Act $map = []; foreach ( $input as $str ) { $map[$str] = 'something computed something'; } $output = []; foreach ( $map as $str => $somthing ) { $output[] = $str; } // Assert foreach ( $output as $str ) { if ( !is_string( $str ) ) { echo "WAT: "; var_dump( $str ); } else { echo "OK: "; var_dump( $str ); } } echo json_encode( $output, JSON_PRETTY_PRINT ); // ------- /** From MediaWiki 1.35 - https://w.wiki/oyY */ function wfRandomString( $length ) : string { $str = ''; for ( $n = 0; $n < $length; $n += 7 ) { $str .= sprintf( '%07x', mt_rand() & 0xfffffff ); } return substr( $str, 0, $length ); }

preferences:
38.56 ms | 402 KiB | 5 Q