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

1.1       misho       1: --TEST--
                      2: Test array_unshift() function : usage variations - double quoted 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:  * double quoted strings for $var argument that is prepended to the array 
                     13:  * passed through $array argument
                     14: */
                     15: 
                     16: echo "*** Testing array_unshift() : double quoted strings for \$var argument ***\n";
                     17: 
                     18: // array to be passed to $array argument
                     19: $array = array('f' => "first", "s" => 'second', 1, 2.222);
                     20: 
                     21: // different variations of double quoted strings to be passed to $var argument
                     22: $vars = array (
                     23:   "\$ -> This represents the dollar sign. hello dollar!!!",
                     24:   "\t\r\v The quick brown fo\fx jumped over the lazy dog",
                     25:   "This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\\",
                     26:   "hello world\\t",
                     27:   "This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t"
                     28: );
                     29: 
                     30: // loop through the various elements of $arrays to test array_unshift()
                     31: $iterator = 1;
                     32: foreach($vars as $var) {
                     33:   echo "-- Iteration $iterator --\n";
                     34:   $temp_array = $array;  // assign $array to another temporary $temp_array
                     35: 
                     36:   /* with default argument */
                     37:   // returns element count in the resulting array after arguments are pushed to
                     38:   // beginning of the given array
                     39:   var_dump( array_unshift($temp_array, $var) );
                     40:   
                     41: // dump the resulting array
                     42:   var_dump($temp_array);
                     43: 
                     44:   /* with optional arguments */
                     45:   // returns element count in the resulting array after arguments are pushed to
                     46:   // beginning of the given array
                     47:   $temp_array = $array;
                     48:   var_dump( array_unshift($temp_array, $var, "hello", 'world') );
                     49:   
                     50:   // dump the resulting array
                     51:   var_dump($temp_array);
                     52:   $iterator++;
                     53: }
                     54: 
                     55: echo "Done";
                     56: ?>
                     57: --EXPECTF--
                     58: *** Testing array_unshift() : double quoted strings for $var argument ***
                     59: -- Iteration 1 --
                     60: int(5)
                     61: array(5) {
                     62:   [0]=>
                     63:   string(53) "$ -> This represents the dollar sign. hello dollar!!!"
                     64:   ["f"]=>
                     65:   string(5) "first"
                     66:   ["s"]=>
                     67:   string(6) "second"
                     68:   [1]=>
                     69:   int(1)
                     70:   [2]=>
                     71:   float(2.222)
                     72: }
                     73: int(7)
                     74: array(7) {
                     75:   [0]=>
                     76:   string(53) "$ -> This represents the dollar sign. hello dollar!!!"
                     77:   [1]=>
                     78:   string(5) "hello"
                     79:   [2]=>
                     80:   string(5) "world"
                     81:   ["f"]=>
                     82:   string(5) "first"
                     83:   ["s"]=>
                     84:   string(6) "second"
                     85:   [3]=>
                     86:   int(1)
                     87:   [4]=>
                     88:   float(2.222)
                     89: }
                     90: -- Iteration 2 --
                     91: int(5)
                     92: array(5) {
                     93:   [0]=>
                     94:   string(49) " 
 The quick brown fox jumped over the lazy dog"
                     95:   ["f"]=>
                     96:   string(5) "first"
                     97:   ["s"]=>
                     98:   string(6) "second"
                     99:   [1]=>
                    100:   int(1)
                    101:   [2]=>
                    102:   float(2.222)
                    103: }
                    104: int(7)
                    105: array(7) {
                    106:   [0]=>
                    107:   string(49) " 
 The quick brown fox jumped over the lazy dog"
                    108:   [1]=>
                    109:   string(5) "hello"
                    110:   [2]=>
                    111:   string(5) "world"
                    112:   ["f"]=>
                    113:   string(5) "first"
                    114:   ["s"]=>
                    115:   string(6) "second"
                    116:   [3]=>
                    117:   int(1)
                    118:   [4]=>
                    119:   float(2.222)
                    120: }
                    121: -- Iteration 3 --
                    122: int(5)
                    123: array(5) {
                    124:   [0]=>
                    125:   string(55) "This is a text with special chars: \!\@\#$\%\^\&\*\(\)\"
                    126:   ["f"]=>
                    127:   string(5) "first"
                    128:   ["s"]=>
                    129:   string(6) "second"
                    130:   [1]=>
                    131:   int(1)
                    132:   [2]=>
                    133:   float(2.222)
                    134: }
                    135: int(7)
                    136: array(7) {
                    137:   [0]=>
                    138:   string(55) "This is a text with special chars: \!\@\#$\%\^\&\*\(\)\"
                    139:   [1]=>
                    140:   string(5) "hello"
                    141:   [2]=>
                    142:   string(5) "world"
                    143:   ["f"]=>
                    144:   string(5) "first"
                    145:   ["s"]=>
                    146:   string(6) "second"
                    147:   [3]=>
                    148:   int(1)
                    149:   [4]=>
                    150:   float(2.222)
                    151: }
                    152: -- Iteration 4 --
                    153: int(5)
                    154: array(5) {
                    155:   [0]=>
                    156:   string(13) "hello world\t"
                    157:   ["f"]=>
                    158:   string(5) "first"
                    159:   ["s"]=>
                    160:   string(6) "second"
                    161:   [1]=>
                    162:   int(1)
                    163:   [2]=>
                    164:   float(2.222)
                    165: }
                    166: int(7)
                    167: array(7) {
                    168:   [0]=>
                    169:   string(13) "hello world\t"
                    170:   [1]=>
                    171:   string(5) "hello"
                    172:   [2]=>
                    173:   string(5) "world"
                    174:   ["f"]=>
                    175:   string(5) "first"
                    176:   ["s"]=>
                    177:   string(6) "second"
                    178:   [3]=>
                    179:   int(1)
                    180:   [4]=>
                    181:   float(2.222)
                    182: }
                    183: -- Iteration 5 --
                    184: int(5)
                    185: array(5) {
                    186:   [0]=>
                    187:   string(70) "This is  a text in bold letters
\s\malong with slashes
                    188:  : HELLO WORLD "
                    189:   ["f"]=>
                    190:   string(5) "first"
                    191:   ["s"]=>
                    192:   string(6) "second"
                    193:   [1]=>
                    194:   int(1)
                    195:   [2]=>
                    196:   float(2.222)
                    197: }
                    198: int(7)
                    199: array(7) {
                    200:   [0]=>
                    201:   string(70) "This is  a text in bold letters
\s\malong with slashes
                    202:  : HELLO WORLD "
                    203:   [1]=>
                    204:   string(5) "hello"
                    205:   [2]=>
                    206:   string(5) "world"
                    207:   ["f"]=>
                    208:   string(5) "first"
                    209:   ["s"]=>
                    210:   string(6) "second"
                    211:   [3]=>
                    212:   int(1)
                    213:   [4]=>
                    214:   float(2.222)
                    215: }
                    216: Done

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