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

1.1       misho       1: --TEST--
                      2: Test array_intersect and array_intersect_assoc behaviour
                      3: --FILE--
                      4: <?php
                      5: //-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=- TEST 1 -=-=-=-=-
                      6: $a = array(1,"big"=>2,2,6,3,5,3,3,454,'some_string',3,3,3,3,3,3,3,3,17);
                      7: $b = array(2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,17,25,'some_string',7,8,9,109,78,17);
                      8: $c = array(-1,2,1,15,25,17);
                      9: echo str_repeat("-=",10)." TEST 1 ".str_repeat("-=",20)."\n";
                     10: echo '$a='.var_export($a,TRUE).";\n";
                     11: echo '$b='.var_export($b,TRUE).";\n";
                     12: echo '$c='.var_export($c,TRUE).";\n";
                     13: 
                     14: echo 'array_intersect($a,$b,$c);'."\n";
                     15: var_dump(array_intersect($a,$b,$c));
                     16: 
                     17: echo 'array_intersect_assoc($a,$b,$c);'."\n";
                     18: var_dump(array_intersect_assoc($a,$b,$c));
                     19: 
                     20: echo 'array_intersect($a,$b);'."\n";
                     21: var_dump(array_intersect($a,$b));
                     22: 
                     23: echo 'array_intersect_assoc($a,$b);'."\n";
                     24: var_dump(array_intersect_assoc($a,$b));
                     25: 
                     26: //-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=- TEST 2 -=-=-=-=-=-
                     27: $a = array(
                     28: 'a'=>2,
                     29: 'b'=>'some',
                     30: 'c'=>'done',
                     31: 'z'=>'foo',
                     32: 'f'=>5,
                     33: 'fan'=>'fen',
                     34: 'bad'=>'bed',
                     35: 'gate'=>'web',
                     36: 7=>18,
                     37: 9=>25,
                     38: 11=>42,
                     39: 12=>42,
                     40: 45=>42,
                     41: 73=>'foo',
                     42: 95=>'some',
                     43: 'som3'=>'some',
                     44: 'want'=>'wanna');
                     45: 
                     46: 
                     47: $b = array(
                     48: 'a'=>7,
                     49: 7=>18,
                     50: 9=>13,
                     51: 11=>42,
                     52: 45=>46,
                     53: 'som3'=>'some',
                     54: 'foo'=>'some',
                     55: 'goo'=>'foo',
                     56: 'f'=>5,
                     57: 'z'=>'equal',
                     58: 'gate'=>'web'
                     59: );
                     60: $c = array(
                     61: 'gate'=>'web',
                     62: 73=>'foo',
                     63: 95=>'some'
                     64: );
                     65: 
                     66: echo str_repeat("-=",10)." TEST 2 ".str_repeat("-=",20)."\n";
                     67: echo '$a='.var_export($a,TRUE).";\n";
                     68: echo '$b='.var_export($b,TRUE).";\n";
                     69: echo '$c='.var_export($c,TRUE).";\n";
                     70: echo "\n\nResults:\n\n";
                     71: 
                     72: echo 'array_intersect($a,$b,$c);'."\n";
                     73: var_dump(array_intersect($a,$b,$c));
                     74: 
                     75: echo 'array_intersect_assoc($a,$b,$c);'."\n";
                     76: var_dump(array_intersect_assoc($a,$b,$c));
                     77: 
                     78: echo 'array_intersect($a,$b);'."\n";
                     79: var_dump(array_intersect($a,$b));
                     80: 
                     81: echo 'array_intersect_assoc($a,$b);'."\n";
                     82: var_dump(array_intersect_assoc($a,$b));
                     83: ?>
                     84: --EXPECT--
                     85: -=-=-=-=-=-=-=-=-=-= TEST 1 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                     86: $a=array (
                     87:   0 => 1,
                     88:   'big' => 2,
                     89:   1 => 2,
                     90:   2 => 6,
                     91:   3 => 3,
                     92:   4 => 5,
                     93:   5 => 3,
                     94:   6 => 3,
                     95:   7 => 454,
                     96:   8 => 'some_string',
                     97:   9 => 3,
                     98:   10 => 3,
                     99:   11 => 3,
                    100:   12 => 3,
                    101:   13 => 3,
                    102:   14 => 3,
                    103:   15 => 3,
                    104:   16 => 3,
                    105:   17 => 17,
                    106: );
                    107: $b=array (
                    108:   0 => 2,
                    109:   1 => 2,
                    110:   2 => 3,
                    111:   3 => 3,
                    112:   4 => 3,
                    113:   5 => 3,
                    114:   6 => 3,
                    115:   7 => 3,
                    116:   8 => 3,
                    117:   9 => 3,
                    118:   10 => 3,
                    119:   11 => 3,
                    120:   12 => 3,
                    121:   13 => 3,
                    122:   14 => 3,
                    123:   15 => 17,
                    124:   16 => 25,
                    125:   17 => 'some_string',
                    126:   18 => 7,
                    127:   19 => 8,
                    128:   20 => 9,
                    129:   21 => 109,
                    130:   22 => 78,
                    131:   23 => 17,
                    132: );
                    133: $c=array (
                    134:   0 => -1,
                    135:   1 => 2,
                    136:   2 => 1,
                    137:   3 => 15,
                    138:   4 => 25,
                    139:   5 => 17,
                    140: );
                    141: array_intersect($a,$b,$c);
                    142: array(3) {
                    143:   ["big"]=>
                    144:   int(2)
                    145:   [1]=>
                    146:   int(2)
                    147:   [17]=>
                    148:   int(17)
                    149: }
                    150: array_intersect_assoc($a,$b,$c);
                    151: array(1) {
                    152:   [1]=>
                    153:   int(2)
                    154: }
                    155: array_intersect($a,$b);
                    156: array(15) {
                    157:   ["big"]=>
                    158:   int(2)
                    159:   [1]=>
                    160:   int(2)
                    161:   [3]=>
                    162:   int(3)
                    163:   [5]=>
                    164:   int(3)
                    165:   [6]=>
                    166:   int(3)
                    167:   [8]=>
                    168:   string(11) "some_string"
                    169:   [9]=>
                    170:   int(3)
                    171:   [10]=>
                    172:   int(3)
                    173:   [11]=>
                    174:   int(3)
                    175:   [12]=>
                    176:   int(3)
                    177:   [13]=>
                    178:   int(3)
                    179:   [14]=>
                    180:   int(3)
                    181:   [15]=>
                    182:   int(3)
                    183:   [16]=>
                    184:   int(3)
                    185:   [17]=>
                    186:   int(17)
                    187: }
                    188: array_intersect_assoc($a,$b);
                    189: array(10) {
                    190:   [1]=>
                    191:   int(2)
                    192:   [3]=>
                    193:   int(3)
                    194:   [5]=>
                    195:   int(3)
                    196:   [6]=>
                    197:   int(3)
                    198:   [9]=>
                    199:   int(3)
                    200:   [10]=>
                    201:   int(3)
                    202:   [11]=>
                    203:   int(3)
                    204:   [12]=>
                    205:   int(3)
                    206:   [13]=>
                    207:   int(3)
                    208:   [14]=>
                    209:   int(3)
                    210: }
                    211: -=-=-=-=-=-=-=-=-=-= TEST 2 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                    212: $a=array (
                    213:   'a' => 2,
                    214:   'b' => 'some',
                    215:   'c' => 'done',
                    216:   'z' => 'foo',
                    217:   'f' => 5,
                    218:   'fan' => 'fen',
                    219:   'bad' => 'bed',
                    220:   'gate' => 'web',
                    221:   7 => 18,
                    222:   9 => 25,
                    223:   11 => 42,
                    224:   12 => 42,
                    225:   45 => 42,
                    226:   73 => 'foo',
                    227:   95 => 'some',
                    228:   'som3' => 'some',
                    229:   'want' => 'wanna',
                    230: );
                    231: $b=array (
                    232:   'a' => 7,
                    233:   7 => 18,
                    234:   9 => 13,
                    235:   11 => 42,
                    236:   45 => 46,
                    237:   'som3' => 'some',
                    238:   'foo' => 'some',
                    239:   'goo' => 'foo',
                    240:   'f' => 5,
                    241:   'z' => 'equal',
                    242:   'gate' => 'web',
                    243: );
                    244: $c=array (
                    245:   'gate' => 'web',
                    246:   73 => 'foo',
                    247:   95 => 'some',
                    248: );
                    249: 
                    250: 
                    251: Results:
                    252: 
                    253: array_intersect($a,$b,$c);
                    254: array(6) {
                    255:   ["b"]=>
                    256:   string(4) "some"
                    257:   ["z"]=>
                    258:   string(3) "foo"
                    259:   ["gate"]=>
                    260:   string(3) "web"
                    261:   [73]=>
                    262:   string(3) "foo"
                    263:   [95]=>
                    264:   string(4) "some"
                    265:   ["som3"]=>
                    266:   string(4) "some"
                    267: }
                    268: array_intersect_assoc($a,$b,$c);
                    269: array(1) {
                    270:   ["gate"]=>
                    271:   string(3) "web"
                    272: }
                    273: array_intersect($a,$b);
                    274: array(11) {
                    275:   ["b"]=>
                    276:   string(4) "some"
                    277:   ["z"]=>
                    278:   string(3) "foo"
                    279:   ["f"]=>
                    280:   int(5)
                    281:   ["gate"]=>
                    282:   string(3) "web"
                    283:   [7]=>
                    284:   int(18)
                    285:   [11]=>
                    286:   int(42)
                    287:   [12]=>
                    288:   int(42)
                    289:   [45]=>
                    290:   int(42)
                    291:   [73]=>
                    292:   string(3) "foo"
                    293:   [95]=>
                    294:   string(4) "some"
                    295:   ["som3"]=>
                    296:   string(4) "some"
                    297: }
                    298: array_intersect_assoc($a,$b);
                    299: array(5) {
                    300:   ["f"]=>
                    301:   int(5)
                    302:   ["gate"]=>
                    303:   string(3) "web"
                    304:   [7]=>
                    305:   int(18)
                    306:   [11]=>
                    307:   int(42)
                    308:   ["som3"]=>
                    309:   string(4) "some"
                    310: }

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