File: array_flip_variation2.phpt

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (97 lines) | stat: -rw-r--r-- 1,973 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
--TEST--
Test array_flip() function : usage variations - 'input' array with different keys
--FILE--
<?php
/*
* Trying different keys in $input array argument
*/

echo "*** Testing array_flip() : different keys for 'input' array argument ***\n";

// different heredoc strings
$empty_heredoc = <<<EOT1
EOT1;

$simple_heredoc = <<<EOT4
simple
EOT4;

$multiline_heredoc = <<<EOT7
multiline heredoc with 123 and
speci@! ch@r$...checking\nand\talso
EOT7;

$input = array(
  // default key
  'one',  //expected: default key 0, value will be replaced by 'bool_key4'

  // numeric keys
  1 => 'int_key', // expected: value will be replaced by 'bool_key3'
  -2 => 'negative_key',
  012 => 'octal_key',
  0x34 => 'hex_key',

  // string keys
  'key' => 'string_key1',
  "two" => 'string_key2',
  '' => 'string_key3',
  "" => 'string_key4',
  " " => 'string_key5',

  // bool keys
  true => 'bool_key1',
  false => 'bool_key2',
  TRUE => 'bool_key3',
  FALSE => 'bool_key4',

  // null keys
  null => 'null_key1',  // expected: value will be replaced by 'null_key2'
  NULL => 'null_key2',

  // binary key
  "a".chr(0)."b" => 'binary_key1',
  b"binary" => 'binary_key2',

  //heredoc keys
  $empty_heredoc => 'empty_heredoc',
  $simple_heredoc => 'simple_heredoc',
  $multiline_heredoc => 'multiline_heredoc',
);

var_dump( array_flip($input) );

echo "Done"
?>
--EXPECTF--
*** Testing array_flip() : different keys for 'input' array argument ***
array(13) {
  ["bool_key4"]=>
  int(0)
  ["bool_key3"]=>
  int(1)
  ["negative_key"]=>
  int(-2)
  ["octal_key"]=>
  int(10)
  ["hex_key"]=>
  int(52)
  ["string_key1"]=>
  string(3) "key"
  ["string_key2"]=>
  string(3) "two"
  ["empty_heredoc"]=>
  string(0) ""
  ["string_key5"]=>
  string(1) " "
  ["binary_key1"]=>
  string(3) "a%0b"
  ["binary_key2"]=>
  string(6) "binary"
  ["simple_heredoc"]=>
  string(6) "simple"
  ["multiline_heredoc"]=>
  string(6%d) "multiline heredoc with 123 and
speci@! ch@r$...checking
and	also"
}
Done