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

1.1       misho       1: --TEST--
                      2: Test array_diff_assoc() function : usage variations - arrays with different data types as keys
                      3: --FILE--
                      4: 
                      5: <?php
                      6: /* Prototype  : array array_diff_assoc(array $arr1, array $arr2 [, array ...])
                      7:  * Description: Returns the entries of arr1 that have values which are not present 
                      8:  * in any of the others arguments but do additional checks whether the keys are equal 
                      9:  * Source code: ext/standard/array.c 
                     10:  */
                     11: 
                     12: /*
                     13:  * Test how array_diff_assoc() compares arrays containing different data types
                     14:  * as keys
                     15:  */
                     16:  
                     17: echo "\n*** Testing array_diff_assoc() : usage variations ***\n";
                     18: 
                     19: $array = array(1, 2, 3);
                     20: 
                     21: //get an unset variable
                     22: $unset_var = 10;
                     23: unset ($unset_var);
                     24: 
                     25: // heredoc string
                     26: $heredoc = <<<EOT
                     27: hello world
                     28: EOT;
                     29: 
                     30: //Different data types as keys to be passed to $arr1 argument
                     31: $inputs = array(
                     32: 
                     33:        // int data
                     34: /*1*/
                     35: 'int' => array(       
                     36:        0 => 'zero',
                     37:        1 => 'one',
                     38:        12345 => 'positive',
                     39:        -2345 => 'negative'),
                     40: 
                     41:        // float data
                     42: /*2*/
                     43: 'float' => array(       
                     44:        10.5 => 'float 1',
                     45:        -10.5 => 'float 2',
                     46:        .5 => 'float 3'),
                     47: 
                     48:        // null data
                     49: /*3*/
                     50: 'null' => array(
                     51:        NULL => 'null 1',
                     52:        null => 'null 2'),
                     53: 
                     54:        // boolean data
                     55: /*4*/
                     56: 'bool' => array(
                     57:        true => 'boolt',
                     58:        false => 'boolf',
                     59:        TRUE => 'boolT',
                     60:        FALSE => 'boolF'),
                     61:        
                     62:        // empty data
                     63: /*5*/
                     64: 'empty' => array(
                     65:       "" => 'emptyd',
                     66:       '' => 'emptys'),
                     67: 
                     68:        // string data
                     69: /*6*/
                     70: 'string' => array(
                     71:       "string" => 'stringd',
                     72:       'string' => 'strings',
                     73:       $heredoc => 'stringh'),
                     74:        
                     75:        // binary data
                     76: /*7*/
                     77: 'binary' => array(
                     78:       b"binary1" => 'binary 1',
                     79:          (binary)"binary2" => 'binary 2'),
                     80: 
                     81:        // undefined data
                     82: /*8*/
                     83: 'undefined' => array(
                     84:       @$undefined_var => 'undefined'),
                     85: 
                     86:        // unset data
                     87: /*9*/
                     88: 'unset' => array(
                     89:       @$unset_var => 'unset'),
                     90: 
                     91: );
                     92: 
                     93: // loop through each element of $inputs to check the behavior of array_diff_assoc
                     94: $iterator = 1;
                     95: foreach($inputs as $key => $input) {
                     96:   echo "\n-- Iteration $iterator --\n";
                     97:   var_dump( array_diff_assoc($input, $array));
                     98:   $iterator++;
                     99: };
                    100: 
                    101: echo "Done";
                    102: ?>
                    103: 
                    104: --EXPECTF--
                    105: 
                    106: *** Testing array_diff_assoc() : usage variations ***
                    107: 
                    108: -- Iteration 1 --
                    109: array(4) {
                    110:   [0]=>
                    111:   string(4) "zero"
                    112:   [1]=>
                    113:   string(3) "one"
                    114:   [12345]=>
                    115:   string(8) "positive"
                    116:   [-2345]=>
                    117:   string(8) "negative"
                    118: }
                    119: 
                    120: -- Iteration 2 --
                    121: array(3) {
                    122:   [10]=>
                    123:   string(7) "float 1"
                    124:   [-10]=>
                    125:   string(7) "float 2"
                    126:   [0]=>
                    127:   string(7) "float 3"
                    128: }
                    129: 
                    130: -- Iteration 3 --
                    131: array(1) {
                    132:   [""]=>
                    133:   string(6) "null 2"
                    134: }
                    135: 
                    136: -- Iteration 4 --
                    137: array(2) {
                    138:   [1]=>
                    139:   string(5) "boolT"
                    140:   [0]=>
                    141:   string(5) "boolF"
                    142: }
                    143: 
                    144: -- Iteration 5 --
                    145: array(1) {
                    146:   [""]=>
                    147:   string(6) "emptys"
                    148: }
                    149: 
                    150: -- Iteration 6 --
                    151: array(2) {
                    152:   ["string"]=>
                    153:   string(7) "strings"
                    154:   ["hello world"]=>
                    155:   string(7) "stringh"
                    156: }
                    157: 
                    158: -- Iteration 7 --
                    159: array(2) {
                    160:   ["binary1"]=>
                    161:   string(8) "binary 1"
                    162:   ["binary2"]=>
                    163:   string(8) "binary 2"
                    164: }
                    165: 
                    166: -- Iteration 8 --
                    167: array(1) {
                    168:   [""]=>
                    169:   string(9) "undefined"
                    170: }
                    171: 
                    172: -- Iteration 9 --
                    173: array(1) {
                    174:   [""]=>
                    175:   string(5) "unset"
                    176: }
                    177: Done

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