-
-
Save danjesus/6085930 to your computer and use it in GitHub Desktop.
Filtrando dados de um array multidimensional
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// array com os dados | |
$data = array( | |
array( | |
"id" => 12, | |
"func" => "João dos Santos", | |
"urgencia" => "Sim", | |
"retirada" => "2013-07-24", | |
"prazo" => 10, | |
"setor" => "Contabilidade" | |
), | |
array( | |
"id" => 13, | |
"func" => "Adriano Toledo", | |
"urgencia" => "Sim", | |
"retirada" => "2013-07-24", | |
"setor" => "Contabilidade" | |
), | |
array( | |
"id" => 14, | |
"func" => "Adriano Toledo", | |
"urgencia" => "Sim", | |
"retirada" => "2013-07-24", | |
"setor" => "Recursos Humanos" | |
), | |
array( | |
"id" => 15, | |
"func" => "Adriano Toledo", | |
"urgencia" => "Sim", | |
"retirada" => "2013-07-24", | |
"setor" => "Caixa" | |
) | |
); | |
$results = array(); | |
foreach ($data as $d) { | |
if (array_key_exists($d['func'], $results)) { | |
$results[$d['func']]++; | |
} else { | |
$results[$d['func']] = 1; | |
} | |
} | |
var_dump($results); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Relatórios</h1> | |
<form action="" method="POST"> | |
<p> | |
Insira a data: <input type="text" name="data"> Formato: YYYY-MM-DD | |
</p> | |
<p> | |
<input type="submit" value="Gerar" name="porDia"> | |
</p> | |
</form> | |
<?php if ($_POST['porDia']): ?> | |
<table> | |
<caption>Total de ordens retiradas em <?= date("d/m/Y", strtotime($_POST['data'])) ?></caption> | |
<thead> | |
<th>Funcionario</th> | |
<th>Quantidade</th> | |
<?php foreach ($view_sql as $sql): ?> | |
<tr> | |
<td><?= $sql['func'] ?></td> | |
<td><?= count($sql['func']) ?></td> | |
</tr> | |
<?php endforeach; ?> | |
</table> | |
<?php endif; ?> | |
/* | |
* Saída de um print_r para ver como os dados são apresentados na view: ordem.phtml; | |
*/ | |
Array | |
( | |
[0] => Array | |
( | |
[id] => 12 | |
[func] => João dos Santos | |
[urgencia] => Sim | |
[retirada] => 2013-07-24 | |
[prazo] => 10 | |
[setor] => Contabilidade | |
) | |
[1] => Array | |
( | |
[id] => 13 | |
[func] => Adriano Toledo | |
[urgencia] => Sim | |
[retirada] => 2013-07-24 | |
[setor] => Contabilidade | |
) | |
[2] => Array | |
( | |
[id] => 14 | |
[func] => Adriano Toledo | |
[urgencia] => Sim | |
[retirada] => 2013-07-24 | |
[setor] => Recursos Humanos | |
) | |
[3] => Array | |
( | |
[id] => 15 | |
[func] => Adriano Toledo | |
[urgencia] => Sim | |
[retirada] => 2013-07-24 | |
[setor] => Caixas | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment