Annotation of embedaddon/php/ext/standard/tests/array/array_rand_variation6.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test array_rand() function : usage variation - with heredoc string as key in the 'input' array
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : mixed array_rand(array $input [, int $num_req])
                      6:  * Description: Return key/keys for random entry/entries in the array 
                      7:  * Source code: ext/standard/array.c
                      8: */
                      9: 
                     10: /*
                     11: * Test behaviour of array_rand() when keys of the 'input' array is heredoc string
                     12: */
                     13: 
                     14: echo "*** Testing array_rand() : with keys of input array as heredoc strings ***\n";
                     15: 
                     16: // defining different heredoc strings
                     17: $empty_heredoc = <<<EOT
                     18: EOT;
                     19: 
                     20: $heredoc_with_newline = <<<EOT
                     21: \n
                     22: EOT;
                     23: 
                     24: $heredoc_with_characters = <<<EOT
                     25: first line of heredoc string
                     26: second line of heredoc string
                     27: third line of heredocstring
                     28: EOT;
                     29: 
                     30: $heredoc_with_newline_and_tabs = <<<EOT
                     31: hello\tworld\nhello\nworld\n
                     32: EOT;
                     33: 
                     34: $heredoc_with_alphanumerics = <<<EOT
                     35: hello123world456
                     36: 1234hello\t1234
                     37: EOT;
                     38: 
                     39: $heredoc_with_embedded_nulls = <<<EOT
                     40: hello\0world\0hello
                     41: \0hello\0
                     42: EOT;
                     43: 
                     44: $input = array(
                     45:   $empty_heredoc => "heredoc1",
                     46:   $heredoc_with_newline => "heredoc2",
                     47:   $heredoc_with_characters => "heredoc3",
                     48:   $heredoc_with_newline_and_tabs => "heredoc3",
                     49:   $heredoc_with_alphanumerics => "heredoc4",
                     50:   $heredoc_with_embedded_nulls => "heredoc5"
                     51: );
                     52: 
                     53: // Test array_rand() function with different valid 'req_num' values
                     54: echo "\n-- with default parameters --\n";
                     55: var_dump( array_rand($input) );
                     56: 
                     57: echo "\n-- with num_req = 1 --\n";
                     58: var_dump( array_rand($input, 1) );
                     59: 
                     60: echo "\n-- with num_req = 3 --\n";
                     61: var_dump( array_rand($input, 3) );
                     62: 
                     63: echo "\n-- with num_req = 6 --\n";
                     64: var_dump( array_rand($input, 6) );
                     65: 
                     66: 
                     67: echo "Done";
                     68: ?>
                     69: --EXPECTREGEX--
                     70: \*\*\* Testing array_rand\(\) : with keys of input array as heredoc strings \*\*\*
                     71: 
                     72: -- with default parameters --
                     73: string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
                     74: 
                     75: -- with num_req = 1 --
                     76: string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
                     77: 
                     78: -- with num_req = 3 --
                     79: array\(3\) {
                     80:   \[0\]=>
                     81:   string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
                     82:   \[1\]=>
                     83:   string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
                     84:   \[2\]=>
                     85:   string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
                     86: }
                     87: 
                     88: -- with num_req = 6 --
                     89: array\(6\) {
                     90:   \[0\]=>
                     91:   string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
                     92:   \[1\]=>
                     93:   string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
                     94:   \[2\]=>
                     95:   string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
                     96:   \[3\]=>
                     97:   string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
                     98:   \[4\]=>
                     99:   string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
                    100:   \[5\]=>
                    101:   string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
                    102: }
                    103: Done
                    104: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>