Skip to content

Instantly share code, notes, and snippets.

View YurePereira's full-sized avatar
😀
Out sick

Yure Pereira YurePereira

😀
Out sick
View GitHub Profile
@YurePereira
YurePereira / using_break_2.php
Created May 26, 2017 19:54
Usando o comando break no laço while e for.
<?php
$contador1 = 0;
while (true) {
echo 'Laço 1: ' . $contador1 . PHP_EOL;
for ($contador2 = 0; $contador2 < 5; $contador2++) {
@YurePereira
YurePereira / using_break.php
Created May 26, 2017 19:33
Usando o comando break no laço while
<?php
$contador = 0;
while (true) {//Loop infinito.
if ($contador >= 5) {
break;
}
@YurePereira
YurePereira / using_for_6.php
Last active May 24, 2017 04:50
Usando o laço de repetição FOR, percorrendo um array 2.
<?php
//Array de elemento
$myArray = array(0, 1, 2, 3, 4);
//Iterando item por item do Array $myArray
for ($i = 0, $length = count($myArray); $i < $length; $i++) {
echo 'Item índice: ' . $i . ', Valor: ' . $myArray[$i] . PHP_EOL;
@YurePereira
YurePereira / using_do_while.php
Last active May 24, 2017 04:23
Usando o laço de repetição DO-WHILE.
<?php
$contador = 0;
do {//Esse bloco será executado pelo menos uma vez.
echo $contador++ . PHP_EOL;
} while ($contador < 5);
@YurePereira
YurePereira / using_foreach.php
Created May 24, 2017 04:00
Usando o laço de repetição FOREACH.
<?php
//Primeira sintaxe:
foreach ($array as $value) {
echo 'Valor: ' . $value . PHP_EOL;
}
//Segunda sintaxe:
foreach ($array as $key => $value) {
echo 'Chave: ' . $key . ', Valor: ' . $value . PHP_EOL;
@YurePereira
YurePereira / using_while.php
Last active May 24, 2017 00:13
Usando o laço de repetição WHILE.
<?php
$contador = 0;
while ($contador < 5) {
echo $contador++ . PHP_EOL;
}
@YurePereira
YurePereira / using_foreach_2.php
Last active May 23, 2017 22:25
Usando o laço de repetição FOREACH, segunda sintaxe.
<?php
$frults = array(
'Pineapple',
'Cashew',
'Apple',
'Strawberry'
);
foreach ($frults as $key => $value) {
@YurePereira
YurePereira / using_foreach_1.php
Last active May 23, 2017 22:12
Usando o laço de repetição FOREACH, primeira sintaxe.
<?php
$frults = array(
'Pineapple',
'Cashew',
'Apple',
'Strawberry'
);
foreach ($frults as $value) {
@YurePereira
YurePereira / using_for_6.php
Last active May 23, 2017 05:02
Usando o laço de repetição FOR, sintaxe alternativa.
<?php
for ($i = 0; $i < 5; $i++):
echo $i . PHP_EOL;
endfor;
/*
Saída:
@YurePereira
YurePereira / using_for_5.php
Created May 23, 2017 04:52
Usando o laço de repetição FOR, percorrendo um array.
<?php
//Array de elemento
$myArray = array(0, 1, 2, 3, 4);
//Iterando item por item do Array $myArray
for ($i = 0; $i < count($myArray); $i++) {
echo 'Item índice: ' . $i . ', Valor: ' . $myArray[$i] . PHP_EOL;