-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathifelse.php
More file actions
71 lines (62 loc) · 1.12 KB
/
ifelse.php
File metadata and controls
71 lines (62 loc) · 1.12 KB
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
<?php
$names = 'Alex, Cris, Elena'; // array
$int = 10; //string
$float = 75.5; //float
$bool = true; //or false //boolean
$null = null; //null
$fruits = ['apple', 'orange', 'banana'];
$user = new stdClass; // object
$file = fopen('text.txt', 'r'); //resource
//Условия if else, switch, case, match
$a = 5;
$b = 2;
$c = 3;
if (1 == $a && 2 == $b || 2 == $a) {
echo "hello world";
} else {
echo "false";
}
// Сокращеный синтаксис
$result = ($a == 1) ? "true" : "false";
echo $result;
if ($a == $b)
echo "Privet";
else
echo "Privet2";
echo ($a) ?: "false";
if ($a == 1) {
echo "true";
} elseif ($a == 2) {
echo "true = 2";
} elseif ($a == 3) {
echo "false2";
} else {
echo "false3";
}
if ($a <= 1)
echo "true";
else
echo "false";
// конструкция switch
switch ($a) {
case 1:
echo "a = 1";
break;
case 2:
echo "a = 2";
break;
case 3:
echo "a = 3";
break;
default:
echo " not avilable";
}
// Конструкция match
$fruit = "pear";
$result = match ($fruit) {
"apple" => "apple",
"orange" => "orange",
"mango" => "mango",
default => "not avilable"
};
echo $result;