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

1.1       misho       1: --TEST--
                      2: Test each() function : usage variations - keys of different data types
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : array each(array $arr)
                      6:  * Description: Return the currently pointed key..value pair in the passed array,
                      7:  * and advance the pointer to the next element 
                      8:  * Source code: Zend/zend_builtin_functions.c
                      9:  */
                     10: 
                     11: /*
                     12:  * Pass each() arrays where the keys are different data types to test behaviour
                     13:  */
                     14: 
                     15: echo "*** Testing each() : usage variations ***\n";
                     16: 
                     17: //get an unset variable
                     18: $unset_var = 10;
                     19: unset ($unset_var);
                     20: 
                     21: // heredoc string
                     22: $heredoc = <<<EOT
                     23: hello world
                     24: EOT;
                     25: 
                     26: // unexpected values to be passed as $arr
                     27: $inputs = array(
                     28: 
                     29:        // int data
                     30: /*1*/  'int' => array(
                     31:        0 => 'zero',
                     32:        1 => 'one',
                     33:        12345 => 'positive',
                     34:        -2345 => 'negative',
                     35:        ),
                     36: 
                     37:        // float data
                     38: /*2*/  'float' => array(
                     39:        10.5 => 'positive',
                     40:        -10.5 => 'negative',
                     41:        .5 => 'half',
                     42:        ),
                     43:        
                     44: /*3*/  'extreme floats' => array(
                     45:        12.3456789000e6 => 'large',
                     46:        12.3456789000E-10 => 'small',
                     47:        ),
                     48: 
                     49:        // null data
                     50: /*4*/ 'null uppercase' => array(
                     51:        NULL => 'null 1',
                     52:        ), 
                     53:        
                     54: /*5*/  'null lowercase' => array(
                     55:        null => 'null 2',
                     56:        ),
                     57: 
                     58:        // boolean data
                     59: /*6*/ 'bool lowercase' => array(
                     60:        true => 'lowert',
                     61:        false => 'lowerf',
                     62:        ),
                     63:        
                     64: /*7*/  'bool uppercase' => array(
                     65:        TRUE => 'uppert',
                     66:        FALSE => 'upperf',
                     67:        ),
                     68:        
                     69:        // empty data
                     70: /*8*/ 'empty double quotes' => array(
                     71:        "" => 'emptyd',
                     72:        ),
                     73:        
                     74: /*9*/  'empty single quotes' => array(
                     75:        '' => 'emptys',
                     76:        ),
                     77: 
                     78:        // string data
                     79: /*10*/ 'string' => array(
                     80:        "stringd" => 'stringd',
                     81:        'strings' => 'strings',
                     82:        $heredoc => 'stringh',
                     83:        ),
                     84: 
                     85:        // undefined data
                     86: /*11*/ 'undefined' => array(
                     87:        @$undefined_var => 'undefined',
                     88:        ),
                     89: 
                     90:        // unset data
                     91: /*12*/ 'unset' => array(
                     92:        @$unset_var => 'unset',
                     93:        ),
                     94: );
                     95: 
                     96: // loop through each element of $inputs to check the behavior of each()
                     97: $iterator = 1;
                     98: foreach($inputs as $key => $input) {
                     99:   echo "\n-- Iteration $iterator: $key data --\n";
                    100:   var_dump( each($input) );
                    101:   $iterator++;
                    102: };
                    103: 
                    104: echo "Done";
                    105: ?>
                    106: 
                    107: --EXPECTF--
                    108: *** Testing each() : usage variations ***
                    109: 
                    110: -- Iteration 1: int data --
                    111: array(4) {
                    112:   [1]=>
                    113:   string(4) "zero"
                    114:   ["value"]=>
                    115:   string(4) "zero"
                    116:   [0]=>
                    117:   int(0)
                    118:   ["key"]=>
                    119:   int(0)
                    120: }
                    121: 
                    122: -- Iteration 2: float data --
                    123: array(4) {
                    124:   [1]=>
                    125:   string(8) "positive"
                    126:   ["value"]=>
                    127:   string(8) "positive"
                    128:   [0]=>
                    129:   int(10)
                    130:   ["key"]=>
                    131:   int(10)
                    132: }
                    133: 
                    134: -- Iteration 3: extreme floats data --
                    135: array(4) {
                    136:   [1]=>
                    137:   string(5) "large"
                    138:   ["value"]=>
                    139:   string(5) "large"
                    140:   [0]=>
                    141:   int(12345678)
                    142:   ["key"]=>
                    143:   int(12345678)
                    144: }
                    145: 
                    146: -- Iteration 4: null uppercase data --
                    147: array(4) {
                    148:   [1]=>
                    149:   string(6) "null 1"
                    150:   ["value"]=>
                    151:   string(6) "null 1"
                    152:   [0]=>
                    153:   string(0) ""
                    154:   ["key"]=>
                    155:   string(0) ""
                    156: }
                    157: 
                    158: -- Iteration 5: null lowercase data --
                    159: array(4) {
                    160:   [1]=>
                    161:   string(6) "null 2"
                    162:   ["value"]=>
                    163:   string(6) "null 2"
                    164:   [0]=>
                    165:   string(0) ""
                    166:   ["key"]=>
                    167:   string(0) ""
                    168: }
                    169: 
                    170: -- Iteration 6: bool lowercase data --
                    171: array(4) {
                    172:   [1]=>
                    173:   string(6) "lowert"
                    174:   ["value"]=>
                    175:   string(6) "lowert"
                    176:   [0]=>
                    177:   int(1)
                    178:   ["key"]=>
                    179:   int(1)
                    180: }
                    181: 
                    182: -- Iteration 7: bool uppercase data --
                    183: array(4) {
                    184:   [1]=>
                    185:   string(6) "uppert"
                    186:   ["value"]=>
                    187:   string(6) "uppert"
                    188:   [0]=>
                    189:   int(1)
                    190:   ["key"]=>
                    191:   int(1)
                    192: }
                    193: 
                    194: -- Iteration 8: empty double quotes data --
                    195: array(4) {
                    196:   [1]=>
                    197:   string(6) "emptyd"
                    198:   ["value"]=>
                    199:   string(6) "emptyd"
                    200:   [0]=>
                    201:   string(0) ""
                    202:   ["key"]=>
                    203:   string(0) ""
                    204: }
                    205: 
                    206: -- Iteration 9: empty single quotes data --
                    207: array(4) {
                    208:   [1]=>
                    209:   string(6) "emptys"
                    210:   ["value"]=>
                    211:   string(6) "emptys"
                    212:   [0]=>
                    213:   string(0) ""
                    214:   ["key"]=>
                    215:   string(0) ""
                    216: }
                    217: 
                    218: -- Iteration 10: string data --
                    219: array(4) {
                    220:   [1]=>
                    221:   string(7) "stringd"
                    222:   ["value"]=>
                    223:   string(7) "stringd"
                    224:   [0]=>
                    225:   string(7) "stringd"
                    226:   ["key"]=>
                    227:   string(7) "stringd"
                    228: }
                    229: 
                    230: -- Iteration 11: undefined data --
                    231: array(4) {
                    232:   [1]=>
                    233:   string(9) "undefined"
                    234:   ["value"]=>
                    235:   string(9) "undefined"
                    236:   [0]=>
                    237:   string(0) ""
                    238:   ["key"]=>
                    239:   string(0) ""
                    240: }
                    241: 
                    242: -- Iteration 12: unset data --
                    243: array(4) {
                    244:   [1]=>
                    245:   string(5) "unset"
                    246:   ["value"]=>
                    247:   string(5) "unset"
                    248:   [0]=>
                    249:   string(0) ""
                    250:   ["key"]=>
                    251:   string(0) ""
                    252: }
                    253: Done

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