Last active
December 19, 2015 06:59
-
-
Save emersonbroga/5915499 to your computer and use it in GitHub Desktop.
Teste de lógica em php dentro de loops em php. É um teste simples que aguça o raciocinio lógico.
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 | |
/** | |
* Use os estilos .last e .last-row | |
* dentro do loop utiliando php | |
* para mostar os grupos conforme as imagens | |
* Grupo 1 : http://cl.ly/image/2r33391j2Q2w/grupo1.png | |
* Grupo 2 : http://cl.ly/image/0s1k0x1S1q2d/grupo2.png | |
* Grupo 3 : http://cl.ly/image/3D0g0a280d1Q/grupo3.png | |
* | |
* | |
* ATENÇÃO: você pode apenas incluir linhas novas, não pode alterar o que já está feito. | |
* (obs: para alternar o grupo, use o parametro GET "?g=1", "?g=2" e "?g=3") | |
* | |
* (c) Emerson Carvalho | |
*/ | |
// cria o grupo 1 | |
$grupo1 = array( | |
'http://placehold.it/100x100&text=Simon', | |
'http://placehold.it/100x100&text=John', | |
'http://placehold.it/100x100&text=Philip', | |
'http://placehold.it/100x100&text=Bart', | |
'http://placehold.it/100x100&text=Matthew', | |
'http://placehold.it/100x100&text=Alphaeus', | |
'http://placehold.it/100x100&text=Judas', | |
'http://placehold.it/100x100&text=James', | |
'http://placehold.it/100x100&text=Zealot', | |
); | |
// cria o grupo 2 | |
$grupo2 = array( | |
'http://placehold.it/100x100&text=Philip', | |
'http://placehold.it/100x100&text=Bart', | |
'http://placehold.it/100x100&text=James', | |
'http://placehold.it/100x100&text=Zealot', | |
); | |
// cria o grupo 3 | |
$grupo3 = array( | |
'http://placehold.it/100x100&text=Philip', | |
'http://placehold.it/100x100&text=Alphaeus', | |
'http://placehold.it/100x100&text=James', | |
); | |
// alterna entre os grupos de acordo com o GET. | |
switch ($_GET['g']){ | |
case '3': | |
$grupo = $grupo3; | |
$title = 'http://placehold.it/400x100&text=GRUPO 3'; | |
$image = 'http://cl.ly/image/3D0g0a280d1Q/grupo3.png'; | |
break; | |
case '2': | |
$grupo = $grupo2; | |
$title = 'http://placehold.it/400x100&text=GRUPO 2'; | |
$image = 'http://cl.ly/image/0s1k0x1S1q2d/grupo2.png'; | |
break; | |
case '1': | |
default: | |
$grupo = $grupo1; | |
$title = 'http://placehold.it/400x100&text=GRUPO 1'; | |
$image = 'http://cl.ly/image/2r33391j2Q2w/grupo1.png'; | |
break; | |
} | |
// declara as variaveis $last e $last_row; | |
$last = ''; | |
$last_row = ''; | |
?> | |
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Teste das bordas</title> | |
<style> | |
.example { padding-top: 20px; } | |
.block {width: 410px; margin: 30px; } | |
.list li { display: block; border-bottom: solid 2px #000; border-right: solid 2px #000; float: left; } | |
.list li img{ margin:10px; } | |
.last { border-right: none !important; } | |
.last-row { border-bottom: none !important; } | |
</style> | |
</head> | |
<body> | |
<div class="block"> | |
<img src="<?php echo $title; ?>"> | |
</div> | |
<!-- inicio do bloco --> | |
<div class="block"> | |
<ul class="list"> | |
<?php foreach($grupo as $url) : ?> | |
<li class="<?php echo $last . $last_row; ?>"><img src="<?php echo $url; ?>"></li> | |
<?php endforeach; ?> | |
</ul> | |
</div> | |
<!-- fim do bloco --> | |
<div class="block"> | |
<img class="example" src="<?php echo $image; ?>"> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment