language/control-structures/match.xml
78d273c6d4b08d0ee04b69bc3a9230a39b99d60f
...
...
@@ -29,6 +29,31 @@ $return_value = match (subject_expression) {
29
29
]]>
30
30
</programlisting>
31
31
32
+
<example>
33
+
<title>Basic <literal>match</literal> usage</title>
34
+
<programlisting role="php">
35
+
<![CDATA[
36
+
<?php
37
+
$food = 'cake';
38
+

39
+
$return_value = match ($food) {
40
+
'apple' => 'This food is an apple',
41
+
'bar' => 'This food is a bar',
42
+
'cake' => 'This food is a cake',
43
+
};
44
+

45
+
var_dump($return_value);
46
+
?>
47
+
]]>
48
+
</programlisting>
49
+
&example.outputs;
50
+
<screen>
51
+
<![CDATA[
52
+
string(19) "This food is a cake"
53
+
]]>
54
+
</screen>
55
+
</example>
56
+

32
57
<note>
33
58
<simpara>
34
59
The result of a <literal>match</literal> expression does not need to be used.
...
...
@@ -60,7 +85,7 @@ $return_value = match (subject_expression) {
60
85
</listitem>
61
86
<listitem>
62
87
<simpara>
63
-
<literal>Match</literal> arms do not fall-through to later cases the way
88
+
<literal>match</literal> arms do not fall-through to later cases the way
64
89
<literal>switch</literal> statements do.
65
90
</simpara>
66
91
</listitem>
...
...
@@ -87,7 +112,7 @@ $return_value = match (subject_expression) {
87
112
<?php
88
113
$result = match ($x) {
89
114
foo() => ...,
90
-
$this->bar() => ..., // bar() isn't called if foo() === $x
115
+
$this->bar() => ..., // $this->bar() isn't called if foo() === $x
91
116
$this->baz => beep(), // beep() isn't called unless $x === $this->baz
92
117
// etc.
93
118
};
94
119