Annotation of embedaddon/php/ext/standard/tests/array/array_unshift_variation9.phpt, revision 1.1.1.2

1.1       misho       1: --TEST--
                      2: Test array_unshift() function : usage variations - heredoc strings for 'var' argument
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : int array_unshift(array $array, mixed $var [, mixed ...])
                      6:  * Description: Pushes elements onto the beginning of the array
                      7:  * Source code: ext/standard/array.c
                      8: */
                      9: 
                     10: /*
                     11:  * Testing the functionality of array_unshift() by passing different
                     12:  * heredoc strings for $var argument that is prepended to the array 
                     13:  * passed through $array argument
                     14: */
                     15: 
                     16: echo "*** Testing array_unshift() : heredoc strings for \$var argument ***\n";
                     17: 
                     18: // heredoc with empty value
                     19: $empty_string = <<<EOT
                     20: EOT;
                     21:   
                     22: // heredoc with blank line
                     23: $blank_line = <<<EOT
                     24: 
                     25: 
                     26: EOT;
                     27:   
                     28: // heredoc with multiline string
                     29: $multiline_string = <<<EOT
                     30: hello world
                     31: The big brown fox jumped over;
                     32: the lazy dog
                     33: This is a double quoted string
                     34: EOT;
                     35: 
1.1.1.2 ! misho      36: // heredoc with different whitespaces
1.1       misho      37: $diff_whitespaces = <<<EOT
                     38: hello\r world\t
                     39: 1111\t\t != 2222\v\v
                     40: heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces
                     41: EOT;
                     42: 
                     43: // heredoc with numeric values
                     44: $numeric_string = <<<EOT
                     45: 11 < 12. 123 >22
                     46: 2222 != 1111.\t 0000 = 0000\n
                     47: EOT;
                     48: 
                     49: // heredoc with quote chars & slash
                     50: $quote_char_string = <<<EOT
                     51: This's a string with quotes:
                     52: "strings in double quote";
                     53: 'strings in single quote';
                     54: this\line is single quoted /with\slashes
                     55: EOT;
                     56: 
                     57: // array to be passed to $array argument
                     58: $array = array('f' => "first", "s" => 'second', 1, 2.222);
                     59: 
                     60: // different heredoc strings to be passed to $var argument
                     61: $vars = array(
                     62:   $empty_string,
                     63:   $blank_line,
                     64:   $multiline_string,
                     65:   $diff_whitespaces,
                     66:   $numeric_string,
                     67:   $quote_char_string
                     68: );
                     69: 
                     70: // loop through the various elements of $arrays to test array_unshift()
                     71: $iterator = 1;
                     72: foreach($vars as $var) {
                     73:   echo "-- Iteration $iterator --\n";
                     74:   $temp_array = $array;  // assign $array to another temporary $temp_array
                     75: 
                     76:   /* with default argument */
                     77:   // returns element count in the resulting array after arguments are pushed to
                     78:   // beginning of the given array
                     79:   var_dump( array_unshift($temp_array, $var) );
                     80:   
                     81:   // dump the resulting array
                     82:   var_dump($temp_array);
                     83: 
                     84:   /* with all possible arguments */
                     85:   // returns element count in the resulting array after arguments are pushed to
                     86:   // beginning of the given array
                     87:   $temp_array = $array;
                     88:   var_dump( array_unshift($temp_array, $var, "hello", 'world') );
                     89:   
                     90:   // dump the resulting array
                     91:   var_dump($temp_array);
                     92:   $iterator++;
                     93: }
                     94: 
                     95: echo "Done";
                     96: ?>
                     97: --EXPECTF--
                     98: *** Testing array_unshift() : heredoc strings for $var argument ***
                     99: -- Iteration 1 --
                    100: int(5)
                    101: array(5) {
                    102:   [0]=>
                    103:   string(0) ""
                    104:   ["f"]=>
                    105:   string(5) "first"
                    106:   ["s"]=>
                    107:   string(6) "second"
                    108:   [1]=>
                    109:   int(1)
                    110:   [2]=>
                    111:   float(2.222)
                    112: }
                    113: int(7)
                    114: array(7) {
                    115:   [0]=>
                    116:   string(0) ""
                    117:   [1]=>
                    118:   string(5) "hello"
                    119:   [2]=>
                    120:   string(5) "world"
                    121:   ["f"]=>
                    122:   string(5) "first"
                    123:   ["s"]=>
                    124:   string(6) "second"
                    125:   [3]=>
                    126:   int(1)
                    127:   [4]=>
                    128:   float(2.222)
                    129: }
                    130: -- Iteration 2 --
                    131: int(5)
                    132: array(5) {
                    133:   [0]=>
                    134:   string(1) "
                    135: "
                    136:   ["f"]=>
                    137:   string(5) "first"
                    138:   ["s"]=>
                    139:   string(6) "second"
                    140:   [1]=>
                    141:   int(1)
                    142:   [2]=>
                    143:   float(2.222)
                    144: }
                    145: int(7)
                    146: array(7) {
                    147:   [0]=>
                    148:   string(1) "
                    149: "
                    150:   [1]=>
                    151:   string(5) "hello"
                    152:   [2]=>
                    153:   string(5) "world"
                    154:   ["f"]=>
                    155:   string(5) "first"
                    156:   ["s"]=>
                    157:   string(6) "second"
                    158:   [3]=>
                    159:   int(1)
                    160:   [4]=>
                    161:   float(2.222)
                    162: }
                    163: -- Iteration 3 --
                    164: int(5)
                    165: array(5) {
                    166:   [0]=>
                    167:   string(86) "hello world
                    168: The big brown fox jumped over;
                    169: the lazy dog
                    170: This is a double quoted string"
                    171:   ["f"]=>
                    172:   string(5) "first"
                    173:   ["s"]=>
                    174:   string(6) "second"
                    175:   [1]=>
                    176:   int(1)
                    177:   [2]=>
                    178:   float(2.222)
                    179: }
                    180: int(7)
                    181: array(7) {
                    182:   [0]=>
                    183:   string(86) "hello world
                    184: The big brown fox jumped over;
                    185: the lazy dog
                    186: This is a double quoted string"
                    187:   [1]=>
                    188:   string(5) "hello"
                    189:   [2]=>
                    190:   string(5) "world"
                    191:   ["f"]=>
                    192:   string(5) "first"
                    193:   ["s"]=>
                    194:   string(6) "second"
                    195:   [3]=>
                    196:   int(1)
                    197:   [4]=>
                    198:   float(2.222)
                    199: }
                    200: -- Iteration 4 --
                    201: int(5)
                    202: array(5) {
                    203:   [0]=>
                    204:   string(88) "hello
 world     
                    205: 1111            != 2222
                    206: heredoc
                    207: double quoted string. withdifferentwhitespaces"
                    208:   ["f"]=>
                    209:   string(5) "first"
                    210:   ["s"]=>
                    211:   string(6) "second"
                    212:   [1]=>
                    213:   int(1)
                    214:   [2]=>
                    215:   float(2.222)
                    216: }
                    217: int(7)
                    218: array(7) {
                    219:   [0]=>
                    220:   string(88) "hello
 world     
                    221: 1111            != 2222
                    222: heredoc
                    223: double quoted string. withdifferentwhitespaces"
                    224:   [1]=>
                    225:   string(5) "hello"
                    226:   [2]=>
                    227:   string(5) "world"
                    228:   ["f"]=>
                    229:   string(5) "first"
                    230:   ["s"]=>
                    231:   string(6) "second"
                    232:   [3]=>
                    233:   int(1)
                    234:   [4]=>
                    235:   float(2.222)
                    236: }
                    237: -- Iteration 5 --
                    238: int(5)
                    239: array(5) {
                    240:   [0]=>
                    241:   string(44) "11 < 12. 123 >22
                    242: 2222 != 1111.   0000 = 0000
                    243: "
                    244:   ["f"]=>
                    245:   string(5) "first"
                    246:   ["s"]=>
                    247:   string(6) "second"
                    248:   [1]=>
                    249:   int(1)
                    250:   [2]=>
                    251:   float(2.222)
                    252: }
                    253: int(7)
                    254: array(7) {
                    255:   [0]=>
                    256:   string(44) "11 < 12. 123 >22
                    257: 2222 != 1111.   0000 = 0000
                    258: "
                    259:   [1]=>
                    260:   string(5) "hello"
                    261:   [2]=>
                    262:   string(5) "world"
                    263:   ["f"]=>
                    264:   string(5) "first"
                    265:   ["s"]=>
                    266:   string(6) "second"
                    267:   [3]=>
                    268:   int(1)
                    269:   [4]=>
                    270:   float(2.222)
                    271: }
                    272: -- Iteration 6 --
                    273: int(5)
                    274: array(5) {
                    275:   [0]=>
                    276:   string(123) "This's a string with quotes:
                    277: "strings in double quote";
                    278: 'strings in single quote';
                    279: this\line is single quoted /with\slashes"
                    280:   ["f"]=>
                    281:   string(5) "first"
                    282:   ["s"]=>
                    283:   string(6) "second"
                    284:   [1]=>
                    285:   int(1)
                    286:   [2]=>
                    287:   float(2.222)
                    288: }
                    289: int(7)
                    290: array(7) {
                    291:   [0]=>
                    292:   string(123) "This's a string with quotes:
                    293: "strings in double quote";
                    294: 'strings in single quote';
                    295: this\line is single quoted /with\slashes"
                    296:   [1]=>
                    297:   string(5) "hello"
                    298:   [2]=>
                    299:   string(5) "world"
                    300:   ["f"]=>
                    301:   string(5) "first"
                    302:   ["s"]=>
                    303:   string(6) "second"
                    304:   [3]=>
                    305:   int(1)
                    306:   [4]=>
                    307:   float(2.222)
                    308: }
                    309: Done

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