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

1.1       misho       1: --TEST--
                      2: Test array_diff_assoc() function : usage variations - strict string comparison check
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : array array_diff_assoc(array $arr1, array $arr2 [, array ...])
                      6:  * Description: Returns the entries of $arr1 that have values which are not 
                      7:  * present in any of the others arguments but do additional checks whether the keys are equal 
                      8:  * Source code: ext/standard/array.c
                      9:  */
                     10: 
                     11: /*
                     12:  * Test how array_diff_assoc behaves
                     13:  * 1. When comparing an array that has similar elements 
                     14:  *    but has been created in a different order
                     15:  * 2. When doing a strict comparison of string representation
                     16:  */
                     17: 
                     18: echo "*** Testing array_diff_assoc() : usage variations ***\n";
                     19: 
                     20: $array = array ('zero', 
                     21:                 1 => 1, 
                     22:                 'two' => 2.00000000000001);
                     23:                 
                     24: $inputs = array (
                     25: 
                     26: //default keys => string values
                     27: /*1*/  array('2.00000000000001', '1', 'zero', 'a'),
                     28:        
                     29: //numeric keys => string values
                     30: /*2*/  array(2 => '2.00000000000001', 
                     31:                  1 => '1', 
                     32:                  0 => 'zero', 
                     33:                  3 => 'a'),
                     34: 
                     35: //string keys => string values
                     36: /*3*/  array('2' => '2.00000000000001', 
                     37:                  '1' => '1', 
                     38:                  '0' => 'zero', 
                     39:                  '3' => 'a') ,
                     40:        
                     41: //default keys => numeric values
                     42: /*4*/  array(2, 1, 0),
                     43:        
                     44: //numeric keys => numeric values
                     45: /*5*/  array(2 => 2,
                     46:                  1 => 1,
                     47:                  0 => 0),
                     48:               
                     49: //string keys => numeric values
                     50: /*6*/  array('two' => 2, 
                     51:                  '1' => 1, 
                     52:                  '0' => 0),
                     53:                  
                     54: //defualt keys => float values
                     55: /*7*/  array(2.00000000000001, 1.00, 0.01E-9),
                     56:                  
                     57: //numeric keys => float values
                     58: /*8*/  array(2 => 2.00000000000001,
                     59:                  1 =>  1.00,
                     60:                  0 => 0.01E-9),
                     61:                  
                     62: //string keys => float values
                     63: /*9*/  array ('two' => 2.00000000000001, 
                     64:                   '1' => 1.00, 
                     65:                   '0' =>0.01E-9)
                     66: );
                     67: 
                     68: // loop through each element of $inputs to check the behavior of array_diff_assoc
                     69: $iterator = 1;
                     70: foreach($inputs as $input) {
                     71:   echo "\n-- Iteration $iterator --\n";
                     72:   var_dump(array_diff_assoc($array, $input));
                     73:   var_dump(array_diff_assoc($input, $array));
                     74:   $iterator++;
                     75: };
                     76: echo "Done";
                     77: ?>
                     78: --EXPECTF--
                     79: *** Testing array_diff_assoc() : usage variations ***
                     80: 
                     81: -- Iteration 1 --
                     82: array(2) {
                     83:   [0]=>
                     84:   string(4) "zero"
                     85:   ["two"]=>
                     86:   float(2)
                     87: }
                     88: array(3) {
                     89:   [0]=>
                     90:   string(16) "2.00000000000001"
                     91:   [2]=>
                     92:   string(4) "zero"
                     93:   [3]=>
                     94:   string(1) "a"
                     95: }
                     96: 
                     97: -- Iteration 2 --
                     98: array(1) {
                     99:   ["two"]=>
                    100:   float(2)
                    101: }
                    102: array(2) {
                    103:   [2]=>
                    104:   string(16) "2.00000000000001"
                    105:   [3]=>
                    106:   string(1) "a"
                    107: }
                    108: 
                    109: -- Iteration 3 --
                    110: array(1) {
                    111:   ["two"]=>
                    112:   float(2)
                    113: }
                    114: array(2) {
                    115:   [2]=>
                    116:   string(16) "2.00000000000001"
                    117:   [3]=>
                    118:   string(1) "a"
                    119: }
                    120: 
                    121: -- Iteration 4 --
                    122: array(2) {
                    123:   [0]=>
                    124:   string(4) "zero"
                    125:   ["two"]=>
                    126:   float(2)
                    127: }
                    128: array(2) {
                    129:   [0]=>
                    130:   int(2)
                    131:   [2]=>
                    132:   int(0)
                    133: }
                    134: 
                    135: -- Iteration 5 --
                    136: array(2) {
                    137:   [0]=>
                    138:   string(4) "zero"
                    139:   ["two"]=>
                    140:   float(2)
                    141: }
                    142: array(2) {
                    143:   [2]=>
                    144:   int(2)
                    145:   [0]=>
                    146:   int(0)
                    147: }
                    148: 
                    149: -- Iteration 6 --
                    150: array(1) {
                    151:   [0]=>
                    152:   string(4) "zero"
                    153: }
                    154: array(1) {
                    155:   [0]=>
                    156:   int(0)
                    157: }
                    158: 
                    159: -- Iteration 7 --
                    160: array(2) {
                    161:   [0]=>
                    162:   string(4) "zero"
                    163:   ["two"]=>
                    164:   float(2)
                    165: }
                    166: array(2) {
                    167:   [0]=>
                    168:   float(2)
                    169:   [2]=>
                    170:   float(1.0E-11)
                    171: }
                    172: 
                    173: -- Iteration 8 --
                    174: array(2) {
                    175:   [0]=>
                    176:   string(4) "zero"
                    177:   ["two"]=>
                    178:   float(2)
                    179: }
                    180: array(2) {
                    181:   [2]=>
                    182:   float(2)
                    183:   [0]=>
                    184:   float(1.0E-11)
                    185: }
                    186: 
                    187: -- Iteration 9 --
                    188: array(1) {
                    189:   [0]=>
                    190:   string(4) "zero"
                    191: }
                    192: array(1) {
                    193:   [0]=>
                    194:   float(1.0E-11)
                    195: }
                    196: Done

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