1--TEST--
2Test array_flip() function : usage variations - 'input' array with different keys
3--FILE--
4<?php
5/* Prototype  : array array_flip(array $input)
6 * Description: Return array with key <-> value flipped
7 * Source code: ext/standard/array.c
8*/
9
10/*
11* Trying different keys in $input array argument
12*/
13
14echo "*** Testing array_flip() : different keys for 'input' array argument ***\n";
15
16// different heredoc strings
17$empty_heredoc = <<<EOT1
18EOT1;
19
20$simple_heredoc = <<<EOT4
21simple
22EOT4;
23
24$multiline_heredoc = <<<EOT7
25multiline heredoc with 123 and
26speci@! ch@r$...checking\nand\talso
27EOT7;
28
29$input = array(
30  // default key
31  'one',  //expected: default key 0, value will be replaced by 'bool_key4'
32
33  // numeric keys
34  1 => 'int_key', // expected: value will be replaced by 'bool_key3'
35  -2 => 'negative_key',
36  8.9 => 'float_key',
37  012 => 'octal_key',
38  0x34 => 'hex_key',
39
40  // string keys
41  'key' => 'string_key1',
42  "two" => 'string_key2',
43  '' => 'string_key3',
44  "" => 'string_key4',
45  " " => 'string_key5',
46
47  // bool keys
48  true => 'bool_key1',
49  false => 'bool_key2',
50  TRUE => 'bool_key3',
51  FALSE => 'bool_key4',
52
53  // null keys
54  null => 'null_key1',  // expected: value will be replaced by 'null_key2'
55  NULL => 'null_key2',
56
57  // binary key
58  "a".chr(0)."b" => 'binary_key1',
59  b"binary" => 'binary_key2',
60
61  //heredoc keys
62  $empty_heredoc => 'empty_heredoc',
63  $simple_heredoc => 'simple_heredoc',
64  $multiline_heredoc => 'multiline_heredoc',
65);
66
67var_dump( array_flip($input) );
68
69echo "Done"
70?>
71--EXPECTF--
72*** Testing array_flip() : different keys for 'input' array argument ***
73array(14) {
74  ["bool_key4"]=>
75  int(0)
76  ["bool_key3"]=>
77  int(1)
78  ["negative_key"]=>
79  int(-2)
80  ["float_key"]=>
81  int(8)
82  ["octal_key"]=>
83  int(10)
84  ["hex_key"]=>
85  int(52)
86  ["string_key1"]=>
87  string(3) "key"
88  ["string_key2"]=>
89  string(3) "two"
90  ["empty_heredoc"]=>
91  string(0) ""
92  ["string_key5"]=>
93  string(1) " "
94  ["binary_key1"]=>
95  string(3) "a�b"
96  ["binary_key2"]=>
97  string(6) "binary"
98  ["simple_heredoc"]=>
99  string(6) "simple"
100  ["multiline_heredoc"]=>
101  string(6%d) "multiline heredoc with 123 and
102speci@! ch@r$...checking
103and	also"
104}
105Done
106