xref: /php-src/Zend/tests/list_keyed.phpt (revision 37c8bb58)
1--TEST--
2list() with keys
3--FILE--
4<?php
5
6$antonyms = [
7    "good" => "bad",
8    "happy" => "sad",
9];
10
11list("good" => $good_antonym, "happy" => $happy_antonym) = $antonyms;
12var_dump($good_antonym, $happy_antonym);
13
14echo PHP_EOL;
15
16$powersOfTwo = [
17    1 => 2,
18    2 => 4,
19    3 => 8
20];
21
22list(1 => $two_1, 2 => $two_2, 3 => $two_3) = $powersOfTwo;
23var_dump($two_1, $two_2, $two_3);
24
25echo PHP_EOL;
26
27$contrivedMixedKeyTypesExample = [
28    7 => "the best PHP version",
29    "elePHPant" => "the cutest mascot"
30];
31
32list(7 => $seven, "elePHPant" => $elePHPant) = $contrivedMixedKeyTypesExample;
33var_dump($seven, $elePHPant);
34
35echo PHP_EOL;
36
37$allTogetherNow = [
38    "antonyms" => $antonyms,
39    "powersOfTwo" => $powersOfTwo,
40    "contrivedMixedKeyTypesExample" => $contrivedMixedKeyTypesExample
41];
42
43list(
44    "antonyms" => list("good" => $good_antonym, "happy" => $happy_antonym),
45    "powersOfTwo" => list(1 => $two_1, 2 => $two_2, 3 => $two_3),
46    "contrivedMixedKeyTypesExample" => list(7 => $seven, "elePHPant" => $elePHPant)
47) = $allTogetherNow;
48
49var_dump($good_antonym, $happy_antonym);
50var_dump($two_1, $two_2, $two_3);
51var_dump($seven, $elePHPant);
52
53?>
54--EXPECT--
55string(3) "bad"
56string(3) "sad"
57
58int(2)
59int(4)
60int(8)
61
62string(20) "the best PHP version"
63string(17) "the cutest mascot"
64
65string(3) "bad"
66string(3) "sad"
67int(2)
68int(4)
69int(8)
70string(20) "the best PHP version"
71string(17) "the cutest mascot"
72