-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
142 lines (140 loc) · 3.67 KB
/
index.php
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE html>
<html>
<head>
<meta name="lang" content="es">
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP7 - reyoculto's guide</title>
<style>
span{
font-weight: bold;
display: block;
width: 100%;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="code-block">
<span>Comparison</span>
<pre>
var_dump(1 === 1);
</pre>
<?php echo var_dump(1 === 1); ?>
</div>
<div class="code-block">
<span>Booleans</span>
<pre>
var_dump( boolval("1") );
</pre>
<?php echo var_dump( boolval("1") ); ?>
</div>
<div class="code-block">
<span>Constantes</span>
<pre>
define("AUTOR", "Reynald Ramirez");
echo "El nombre del autor es: ". AUTOR;
</pre>
<?php
define("AUTOR", "Reynald Ramirez");
echo "El nombre del autor es: ". AUTOR;
?>
</div>
<div class="code-block">
<span>Constantes con true (permite ser minuscula)</span>
<pre>
define("AUTOR", "Reynald", true);
echo "El nombre del autor es: ". autor;
</pre>
<?php
define("AUTOR", "Reynald", true);
echo "El nombre del autor es: ". autor;
?>
</div>
<div class="code-block">
<span>Constantes predefinidas</span>
<pre>
echo "El nombre y ruta de este archivo es: ". __FILE__;
</pre>
<?php
echo "El nombre y ruta de este archivo es: ". __FILE__;
?>
</div>
<div class="code-block">
<span>String comparison (===)</span>
<pre>
$operacion = "Suma";
if(!strcmp("Suma", $operacion)){
echo "Estamos listos para realizar una suma ";
}
</pre>
<?php
$operacion = "Suma";
if(!strcmp("Suma", $operacion)){
echo "Estamos listos para realizar una suma ";
}
?>
</div>
<div class="code-block">
<span>String comparison (==)</span>
<pre>
$operacion = "SUMA";
if(!strcasecmp("Suma", $operacion)){
echo "Estamos listos para realizar una suma ";
}
// strcasecmp() & strcmp() returns 0 if true and 1 if false
</pre>
<?php
$operacion = "SUMA";
if(!strcasecmp("Suma", $operacion)){
echo "Estamos listos para realizar una suma de SUMA ";
}
?>
</div>
<div class="code-block">
<span>getrandmax()</span>
<pre>
echo getrandmax();
</pre>
<?php
echo getrandmax(); // Devuelve el valor maximo que puede generar la llamada a rand()
?>
</div>
<div class="code-block">
<span>rand()</span>
<pre>
echo rand();
</pre>
<?php
echo rand();
// Devuelve un valor aleatorio
// a esta funcion se le puede pasar dos parametros: min y max => rand(min, max)
// rand(0,10) // devolveria un valor aleatorio entre 0 y 10
?>
</div>
<div class="code-block">
<span>Casting</span>
<pre>
$num1 = "5";
echo (int) $num1;
</pre>
<?php
$num1 = "5";
$num1 = (int) $num1;
echo gettype($num1);
// El lenguaje PHP es implicito por lo tanto, interpreta el tipo de una variable por su contenido sin que esta lo exprese de manera directa
?>
<div class="code-block">
<span>Casting</span>
<pre>
$num3 = "3778.50";
echo number_format($num3);
</pre>
<?php
$num3 = "3778.50";
echo number_format($num3, 2, '.', ',');
// El lenguaje PHP es implicito por lo tanto, interpreta el tipo de una variable por su contenido sin que esta lo exprese de manera directa
?>
</div>
</body>
</html>