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

1.1       misho       1: --TEST--
                      2: Test array_reverse() function : usage variations - assoc. array with diff. value for 'array' argument
                      3: --INI--
                      4: precision=12
                      5: --FILE--
                      6: <?php
                      7: /* Prototype  : array array_reverse(array $array [, bool $preserve_keys])
                      8:  * Description: Return input as a new array with the order of the entries reversed
                      9:  * Source code: ext/standard/array.c
                     10: */
                     11: 
                     12: /*
                     13:  * Testing the functionality of array_reverse() by giving associative arrays with different
                     14:  * values for $array argument
                     15: */
                     16: 
                     17: echo "*** Testing array_reverse() : usage variations ***\n";
                     18: 
                     19: //get an unset variable
                     20: $unset_var = 10;
                     21: unset ($unset_var);
                     22: 
                     23: //get a resource variable
                     24: $fp = fopen(__FILE__, "r");
                     25: 
                     26: //get a class
                     27: class classA
                     28: {
                     29:   public function __toString(){
                     30:     return "Class A object";
                     31:   }
                     32: }
                     33: 
                     34: // get a heredoc string
                     35: $heredoc = <<<EOT
                     36: Hello world
                     37: EOT;
                     38: 
                     39: // initializing the array
                     40: $arrays = array (
                     41: 
                     42:        // empty array
                     43: /*1*/  array(),
                     44: 
                     45:        // arrays with integer values
                     46:        array('0' => 0),
                     47:        array("1" => 1),
                     48:        array("one" => 1, 'two' => 2, "three" => 3, 4 => 4),
                     49:  
                     50:        // arrays with float values
                     51: /*5*/  array("float" => 2.3333),
                     52:        array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333333),
                     53:   
                     54:        // arrays with string values
                     55:        array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 =>  "pen\n"),
                     56: /*8*/  array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 =>  'pen\n'), 
                     57:        array(1 => "hello", "heredoc" => $heredoc),
                     58: 
                     59:        // array with object, unset variable and resource variable
                     60:        array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), 
                     61: 
                     62:        // array with mixed values
                     63: /*11*/ array(1 => 'hello', 2 => new classA(), 222 => "fruit", 'resource' => $fp, "int" => 133, "float" => 444.432, "unset" => @$unset_var, "heredoc" => $heredoc)
                     64: );
                     65: 
                     66: // loop through the various elements of $arrays to test array_reverse()
                     67: $iterator = 1;
                     68: foreach($arrays as $array) {
                     69:   echo "-- Iteration $iterator --\n";
                     70:   // with default argument
                     71:   echo "- default argument -\n";
                     72:   var_dump( array_reverse($array) );
                     73:   // with $preserve_keys argument
                     74:   echo "- \$preserve keys = true -\n";
                     75:   var_dump( array_reverse($array, true) );
                     76:   echo "- \$preserve_keys = false -\n";
                     77:   var_dump( array_reverse($array, false) );
                     78:   $iterator++;
                     79: };
                     80: 
                     81: // close the file resource used
                     82: fclose($fp);
                     83: 
                     84: echo "Done";
                     85: ?>
                     86: --EXPECTF--
                     87: *** Testing array_reverse() : usage variations ***
                     88: -- Iteration 1 --
                     89: - default argument -
                     90: array(0) {
                     91: }
                     92: - $preserve keys = true -
                     93: array(0) {
                     94: }
                     95: - $preserve_keys = false -
                     96: array(0) {
                     97: }
                     98: -- Iteration 2 --
                     99: - default argument -
                    100: array(1) {
                    101:   [0]=>
                    102:   int(0)
                    103: }
                    104: - $preserve keys = true -
                    105: array(1) {
                    106:   [0]=>
                    107:   int(0)
                    108: }
                    109: - $preserve_keys = false -
                    110: array(1) {
                    111:   [0]=>
                    112:   int(0)
                    113: }
                    114: -- Iteration 3 --
                    115: - default argument -
                    116: array(1) {
                    117:   [0]=>
                    118:   int(1)
                    119: }
                    120: - $preserve keys = true -
                    121: array(1) {
                    122:   [1]=>
                    123:   int(1)
                    124: }
                    125: - $preserve_keys = false -
                    126: array(1) {
                    127:   [0]=>
                    128:   int(1)
                    129: }
                    130: -- Iteration 4 --
                    131: - default argument -
                    132: array(4) {
                    133:   [0]=>
                    134:   int(4)
                    135:   ["three"]=>
                    136:   int(3)
                    137:   ["two"]=>
                    138:   int(2)
                    139:   ["one"]=>
                    140:   int(1)
                    141: }
                    142: - $preserve keys = true -
                    143: array(4) {
                    144:   [4]=>
                    145:   int(4)
                    146:   ["three"]=>
                    147:   int(3)
                    148:   ["two"]=>
                    149:   int(2)
                    150:   ["one"]=>
                    151:   int(1)
                    152: }
                    153: - $preserve_keys = false -
                    154: array(4) {
                    155:   [0]=>
                    156:   int(4)
                    157:   ["three"]=>
                    158:   int(3)
                    159:   ["two"]=>
                    160:   int(2)
                    161:   ["one"]=>
                    162:   int(1)
                    163: }
                    164: -- Iteration 5 --
                    165: - default argument -
                    166: array(1) {
                    167:   ["float"]=>
                    168:   float(2.3333)
                    169: }
                    170: - $preserve keys = true -
                    171: array(1) {
                    172:   ["float"]=>
                    173:   float(2.3333)
                    174: }
                    175: - $preserve_keys = false -
                    176: array(1) {
                    177:   ["float"]=>
                    178:   float(2.3333)
                    179: }
                    180: -- Iteration 6 --
                    181: - default argument -
                    182: array(4) {
                    183:   ["f4"]=>
                    184:   float(33333333.3333)
                    185:   [0]=>
                    186:   float(4.8999992284)
                    187:   ["f2"]=>
                    188:   float(3.33)
                    189:   ["f1"]=>
                    190:   float(1.2)
                    191: }
                    192: - $preserve keys = true -
                    193: array(4) {
                    194:   ["f4"]=>
                    195:   float(33333333.3333)
                    196:   [3]=>
                    197:   float(4.8999992284)
                    198:   ["f2"]=>
                    199:   float(3.33)
                    200:   ["f1"]=>
                    201:   float(1.2)
                    202: }
                    203: - $preserve_keys = false -
                    204: array(4) {
                    205:   ["f4"]=>
                    206:   float(33333333.3333)
                    207:   [0]=>
                    208:   float(4.8999992284)
                    209:   ["f2"]=>
                    210:   float(3.33)
                    211:   ["f1"]=>
                    212:   float(1.2)
                    213: }
                    214: -- Iteration 7 --
                    215: - default argument -
                    216: array(4) {
                    217:   [0]=>
                    218:   string(4) "pen
                    219: "
                    220:   [1]=>
                    221:   string(7) "world"
                    222:   ["red"]=>
                    223:   string(6) "col       or"
                    224:   [2]=>
                    225:   string(6) "  Hello"
                    226: }
                    227: - $preserve keys = true -
                    228: array(4) {
                    229:   [3]=>
                    230:   string(4) "pen
                    231: "
                    232:   [2]=>
                    233:   string(7) "world"
                    234:   ["red"]=>
                    235:   string(6) "col       or"
                    236:   [111]=>
                    237:   string(6) "  Hello"
                    238: }
                    239: - $preserve_keys = false -
                    240: array(4) {
                    241:   [0]=>
                    242:   string(4) "pen
                    243: "
                    244:   [1]=>
                    245:   string(7) "world"
                    246:   ["red"]=>
                    247:   string(6) "col       or"
                    248:   [2]=>
                    249:   string(6) "  Hello"
                    250: }
                    251: -- Iteration 8 --
                    252: - default argument -
                    253: array(4) {
                    254:   [0]=>
                    255:   string(5) "pen\n"
                    256:   [1]=>
                    257:   string(9) "\v\fworld"
                    258:   ["red"]=>
                    259:   string(7) "col\tor"
                    260:   [2]=>
                    261:   string(7) "\tHello"
                    262: }
                    263: - $preserve keys = true -
                    264: array(4) {
                    265:   [3]=>
                    266:   string(5) "pen\n"
                    267:   [2]=>
                    268:   string(9) "\v\fworld"
                    269:   ["red"]=>
                    270:   string(7) "col\tor"
                    271:   [111]=>
                    272:   string(7) "\tHello"
                    273: }
                    274: - $preserve_keys = false -
                    275: array(4) {
                    276:   [0]=>
                    277:   string(5) "pen\n"
                    278:   [1]=>
                    279:   string(9) "\v\fworld"
                    280:   ["red"]=>
                    281:   string(7) "col\tor"
                    282:   [2]=>
                    283:   string(7) "\tHello"
                    284: }
                    285: -- Iteration 9 --
                    286: - default argument -
                    287: array(2) {
                    288:   ["heredoc"]=>
                    289:   string(11) "Hello world"
                    290:   [0]=>
                    291:   string(5) "hello"
                    292: }
                    293: - $preserve keys = true -
                    294: array(2) {
                    295:   ["heredoc"]=>
                    296:   string(11) "Hello world"
                    297:   [1]=>
                    298:   string(5) "hello"
                    299: }
                    300: - $preserve_keys = false -
                    301: array(2) {
                    302:   ["heredoc"]=>
                    303:   string(11) "Hello world"
                    304:   [0]=>
                    305:   string(5) "hello"
                    306: }
                    307: -- Iteration 10 --
                    308: - default argument -
                    309: array(3) {
                    310:   ["resource"]=>
                    311:   resource(%d) of type (stream)
                    312:   ["unset"]=>
                    313:   NULL
                    314:   [0]=>
                    315:   object(classA)#%d (0) {
                    316:   }
                    317: }
                    318: - $preserve keys = true -
                    319: array(3) {
                    320:   ["resource"]=>
                    321:   resource(%d) of type (stream)
                    322:   ["unset"]=>
                    323:   NULL
                    324:   [11]=>
                    325:   object(classA)#%d (0) {
                    326:   }
                    327: }
                    328: - $preserve_keys = false -
                    329: array(3) {
                    330:   ["resource"]=>
                    331:   resource(%d) of type (stream)
                    332:   ["unset"]=>
                    333:   NULL
                    334:   [0]=>
                    335:   object(classA)#%d (0) {
                    336:   }
                    337: }
                    338: -- Iteration 11 --
                    339: - default argument -
                    340: array(8) {
                    341:   ["heredoc"]=>
                    342:   string(11) "Hello world"
                    343:   ["unset"]=>
                    344:   NULL
                    345:   ["float"]=>
                    346:   float(444.432)
                    347:   ["int"]=>
                    348:   int(133)
                    349:   ["resource"]=>
                    350:   resource(%d) of type (stream)
                    351:   [0]=>
                    352:   string(5) "fruit"
                    353:   [1]=>
                    354:   object(classA)#%d (0) {
                    355:   }
                    356:   [2]=>
                    357:   string(5) "hello"
                    358: }
                    359: - $preserve keys = true -
                    360: array(8) {
                    361:   ["heredoc"]=>
                    362:   string(11) "Hello world"
                    363:   ["unset"]=>
                    364:   NULL
                    365:   ["float"]=>
                    366:   float(444.432)
                    367:   ["int"]=>
                    368:   int(133)
                    369:   ["resource"]=>
                    370:   resource(%d) of type (stream)
                    371:   [222]=>
                    372:   string(5) "fruit"
                    373:   [2]=>
                    374:   object(classA)#%d (0) {
                    375:   }
                    376:   [1]=>
                    377:   string(5) "hello"
                    378: }
                    379: - $preserve_keys = false -
                    380: array(8) {
                    381:   ["heredoc"]=>
                    382:   string(11) "Hello world"
                    383:   ["unset"]=>
                    384:   NULL
                    385:   ["float"]=>
                    386:   float(444.432)
                    387:   ["int"]=>
                    388:   int(133)
                    389:   ["resource"]=>
                    390:   resource(%d) of type (stream)
                    391:   [0]=>
                    392:   string(5) "fruit"
                    393:   [1]=>
                    394:   object(classA)#%d (0) {
                    395:   }
                    396:   [2]=>
                    397:   string(5) "hello"
                    398: }
                    399: Done

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