-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunciones.class.php
More file actions
61 lines (55 loc) · 1.36 KB
/
Funciones.class.php
File metadata and controls
61 lines (55 loc) · 1.36 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
<?php
class Funciones
{
/**
* para usar en vez de mysqli_query (para extraer datos)
*/
public function mysqli_to_array($conexion, $sql, $primerRegistro = false)
{
$res = mysqli_query($conexion, $sql);
$rows = array();
if (is_object($res)) {
if ($primerRegistro) { //true si solo devuelve un registro
$rows = mysqli_fetch_assoc($res);
} else {
while ($row = mysqli_fetch_assoc($res)) {
$rows[] = $row;
}
}
}
return $rows;
}
/**
* Para buscar un dato en un array asociativo
*/
public function in_asociative_array($array, $key, $key_value)
{
$within_array = false;
foreach ($array as $k => $v) {
if (is_array($v)) {
$within_array = in_asociative_array($v, $key, $key_value);
if ($within_array == true) {
break;
}
} else {
if ($v == $key_value && $k == $key) {
$within_array = true;
break;
}
}
}
return $within_array;
}
}
/* ejemplo de uso de in_asociative_array */
$trucomands[] = array(
array('msgtext' => 'pepe', 'cantidad' => '2'),
array('msgtext' => 'pepa', 'cantidad' => '5'),
array('msgtext' => 'pipa', 'cantidad' => '1')
);
$f = new Funciones();
if ($f->in_asociative_array($trucomands, 'msgtext', 'pepe')) {
return true;
} else {
return false;
}