Annotation of embedaddon/php/ext/standard/tests/array/array_combine_variation3.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test array_combine() function : usage variations - different arrays(Bug#43424)
        !             3: --FILE--
        !             4: <?php
        !             5: /* Prototype  : array array_combine(array $keys, array $values)
        !             6:  * Description: Creates an array by using the elements of the first parameter as keys
        !             7:  *              and the elements of the second as the corresponding values
        !             8:  * Source code: ext/standard/array.c
        !             9: */
        !            10: 
        !            11: /*
        !            12: * Passing different types of arrays to both $keys and $values arguments and testing whether 
        !            13: * array_combine() behaves in an expected way with the arguments passed to the function
        !            14: */
        !            15: 
        !            16: echo "*** Testing array_combine() : Passing different types of arrays to both \$keys and \$values argument ***\n";
        !            17: /* Different heredoc strings passed as argument to arrays */
        !            18: // heredoc with blank line
        !            19: $blank_line = <<<EOT
        !            20: 
        !            21: 
        !            22: EOT;
        !            23: 
        !            24: // heredoc with multiline string
        !            25: $multiline_string = <<<EOT
        !            26: hello world
        !            27: The quick brown fox jumped over;
        !            28: the lazy dog
        !            29: This is a double quoted string
        !            30: EOT;
        !            31: 
        !            32: // heredoc with diferent whitespaces
        !            33: $diff_whitespaces = <<<EOT
        !            34: hello\r world\t
        !            35: 1111\t\t != 2222\v\v
        !            36: heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces
        !            37: EOT;
        !            38: 
        !            39: // heredoc with quoted strings and numeric values
        !            40: $numeric_string = <<<EOT
        !            41: 11 < 12. 123 >22
        !            42: 'single quoted string'
        !            43: "double quoted string"
        !            44: 2222 != 1111.\t 0000 = 0000\n
        !            45: EOT;
        !            46: 
        !            47: // arrays passed to $keys argument
        !            48: $arrays = array (
        !            49: /*1*/  array(1, 2), // with default keys and numeric values
        !            50:        array(1.1, 2.2), // with default keys & float values
        !            51:        array(false,true), // with default keys and boolean values
        !            52:        array(), // empty array
        !            53: /*5*/  array(NULL), // with NULL
        !            54:        array("a\v\f","aaaa\r","b","b\tbbb","c","\[\]\!\@\#\$\%\^\&\*\(\)\{\}"),  // with double quoted strings
        !            55:        array('a\v\f','aaaa\r','b','b\tbbb','c','\[\]\!\@\#\$\%\^\&\*\(\)\{\}'),  // with single quoted strings
        !            56:        array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $numeric_string),  // with heredocs
        !            57: 
        !            58:        // associative arrays
        !            59: /*9*/  array(1 => "one", 2 => "two", 3 => "three"),  // explicit numeric keys, string values
        !            60:        array("one" => 1, "two" => 2, "three" => 3 ),  // string keys & numeric values
        !            61:        array( 1 => 10, 2 => 20, 4 => 40, 3 => 30),  // explicit numeric keys and numeric values
        !            62:        array( "one" => "ten", "two" => "twenty", "three" => "thirty"),  // string key/value
        !            63:        array("one" => 1, 2 => "two", 4 => "four"),  //mixed
        !            64: 
        !            65:        // associative array, containing null/empty/boolean values as key/value
        !            66: /*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null),
        !            67:        array(true => "true", false => "false", "false" => false, "true" => true),
        !            68:        array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''),
        !            69:        array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true),
        !            70:        array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6),
        !            71: 
        !            72:        // array with repetative keys
        !            73: /*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3)
        !            74: );
        !            75: 
        !            76: // loop through each sub-array within $arrays to check the behavior of array_combine()
        !            77: // same arrays are passed to both $keys and $values
        !            78: $iterator = 1;
        !            79: foreach($arrays as $array) {
        !            80:   echo "-- Iteration $iterator --\n";
        !            81:   var_dump( array_combine($array, $array) );
        !            82:   $iterator++;
        !            83: }
        !            84: 
        !            85: echo "Done";
        !            86: ?>
        !            87: --EXPECTF--
        !            88: *** Testing array_combine() : Passing different types of arrays to both $keys and $values argument ***
        !            89: -- Iteration 1 --
        !            90: array(2) {
        !            91:   [1]=>
        !            92:   int(1)
        !            93:   [2]=>
        !            94:   int(2)
        !            95: }
        !            96: -- Iteration 2 --
        !            97: array(2) {
        !            98:   ["1.1"]=>
        !            99:   float(1.1)
        !           100:   ["2.2"]=>
        !           101:   float(2.2)
        !           102: }
        !           103: -- Iteration 3 --
        !           104: array(2) {
        !           105:   [""]=>
        !           106:   bool(false)
        !           107:   [1]=>
        !           108:   bool(true)
        !           109: }
        !           110: -- Iteration 4 --
        !           111: 
        !           112: Warning: array_combine(): Both parameters should have at least 1 element in %s on line %d
        !           113: bool(false)
        !           114: -- Iteration 5 --
        !           115: array(1) {
        !           116:   [""]=>
        !           117:   NULL
        !           118: }
        !           119: -- Iteration 6 --
        !           120: array(6) {
        !           121:   ["a"]=>
        !           122:   string(3) "a"
        !           123:   ["aaaa
"]=>
        !           124:   string(5) "aaaa
"
        !           125:   ["b"]=>
        !           126:   string(1) "b"
        !           127:   ["b  bbb"]=>
        !           128:   string(5) "b bbb"
        !           129:   ["c"]=>
        !           130:   string(1) "c"
        !           131:   ["\[\]\!\@\#$\%\^\&\*\(\)\{\}"]=>
        !           132:   string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}"
        !           133: }
        !           134: -- Iteration 7 --
        !           135: array(6) {
        !           136:   ["a\v\f"]=>
        !           137:   string(5) "a\v\f"
        !           138:   ["aaaa\r"]=>
        !           139:   string(6) "aaaa\r"
        !           140:   ["b"]=>
        !           141:   string(1) "b"
        !           142:   ["b\tbbb"]=>
        !           143:   string(6) "b\tbbb"
        !           144:   ["c"]=>
        !           145:   string(1) "c"
        !           146:   ["\[\]\!\@\#\$\%\^\&\*\(\)\{\}"]=>
        !           147:   string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"
        !           148: }
        !           149: -- Iteration 8 --
        !           150: array(4) {
        !           151:   ["
        !           152: "]=>
        !           153:   string(1) "
        !           154: "
        !           155:   ["hello world
        !           156: The quick brown fox jumped over;
        !           157: the lazy dog
        !           158: This is a double quoted string"]=>
        !           159:   string(88) "hello world
        !           160: The quick brown fox jumped over;
        !           161: the lazy dog
        !           162: This is a double quoted string"
        !           163:   ["hello
 world       
        !           164: 1111            != 2222
        !           165: heredoc
        !           166: double quoted string. withdifferentwhitespaces"]=>
        !           167:   string(88) "hello
 world     
        !           168: 1111            != 2222
        !           169: heredoc
        !           170: double quoted string. withdifferentwhitespaces"
        !           171:   ["11 < 12. 123 >22
        !           172: 'single quoted string'
        !           173: "double quoted string"
        !           174: 2222 != 1111.   0000 = 0000
        !           175: "]=>
        !           176:   string(90) "11 < 12. 123 >22
        !           177: 'single quoted string'
        !           178: "double quoted string"
        !           179: 2222 != 1111.   0000 = 0000
        !           180: "
        !           181: }
        !           182: -- Iteration 9 --
        !           183: array(3) {
        !           184:   ["one"]=>
        !           185:   string(3) "one"
        !           186:   ["two"]=>
        !           187:   string(3) "two"
        !           188:   ["three"]=>
        !           189:   string(5) "three"
        !           190: }
        !           191: -- Iteration 10 --
        !           192: array(3) {
        !           193:   [1]=>
        !           194:   int(1)
        !           195:   [2]=>
        !           196:   int(2)
        !           197:   [3]=>
        !           198:   int(3)
        !           199: }
        !           200: -- Iteration 11 --
        !           201: array(4) {
        !           202:   [10]=>
        !           203:   int(10)
        !           204:   [20]=>
        !           205:   int(20)
        !           206:   [40]=>
        !           207:   int(40)
        !           208:   [30]=>
        !           209:   int(30)
        !           210: }
        !           211: -- Iteration 12 --
        !           212: array(3) {
        !           213:   ["ten"]=>
        !           214:   string(3) "ten"
        !           215:   ["twenty"]=>
        !           216:   string(6) "twenty"
        !           217:   ["thirty"]=>
        !           218:   string(6) "thirty"
        !           219: }
        !           220: -- Iteration 13 --
        !           221: array(3) {
        !           222:   [1]=>
        !           223:   int(1)
        !           224:   ["two"]=>
        !           225:   string(3) "two"
        !           226:   ["four"]=>
        !           227:   string(4) "four"
        !           228: }
        !           229: -- Iteration 14 --
        !           230: array(2) {
        !           231:   ["null"]=>
        !           232:   string(4) "null"
        !           233:   [""]=>
        !           234:   NULL
        !           235: }
        !           236: -- Iteration 15 --
        !           237: array(4) {
        !           238:   ["true"]=>
        !           239:   string(4) "true"
        !           240:   ["false"]=>
        !           241:   string(5) "false"
        !           242:   [""]=>
        !           243:   bool(false)
        !           244:   [1]=>
        !           245:   bool(true)
        !           246: }
        !           247: -- Iteration 16 --
        !           248: array(2) {
        !           249:   ["emptys"]=>
        !           250:   string(6) "emptys"
        !           251:   [""]=>
        !           252:   string(0) ""
        !           253: }
        !           254: -- Iteration 17 --
        !           255: array(2) {
        !           256:   [""]=>
        !           257:   bool(false)
        !           258:   [1]=>
        !           259:   bool(true)
        !           260: }
        !           261: -- Iteration 18 --
        !           262: array(3) {
        !           263:   [4]=>
        !           264:   int(4)
        !           265:   [5]=>
        !           266:   int(5)
        !           267:   [6]=>
        !           268:   int(6)
        !           269: }
        !           270: -- Iteration 19 --
        !           271: array(3) {
        !           272:   [10]=>
        !           273:   int(10)
        !           274:   [20]=>
        !           275:   int(20)
        !           276:   [3]=>
        !           277:   int(3)
        !           278: }
        !           279: Done

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