This file contains hidden or 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 | |
| $contador1 = 0; | |
| while (true) { | |
| echo 'Laço 1: ' . $contador1 . PHP_EOL; | |
| for ($contador2 = 0; $contador2 < 5; $contador2++) { | |
This file contains hidden or 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 | |
| $contador = 0; | |
| while (true) {//Loop infinito. | |
| if ($contador >= 5) { | |
| break; | |
| } | |
This file contains hidden or 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 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; | |
This file contains hidden or 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 | |
| $contador = 0; | |
| do {//Esse bloco será executado pelo menos uma vez. | |
| echo $contador++ . PHP_EOL; | |
| } while ($contador < 5); |
This file contains hidden or 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 | |
| //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; |
This file contains hidden or 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 | |
| $contador = 0; | |
| while ($contador < 5) { | |
| echo $contador++ . PHP_EOL; | |
| } |
This file contains hidden or 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 | |
| $frults = array( | |
| 'Pineapple', | |
| 'Cashew', | |
| 'Apple', | |
| 'Strawberry' | |
| ); | |
| foreach ($frults as $key => $value) { |
This file contains hidden or 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 | |
| $frults = array( | |
| 'Pineapple', | |
| 'Cashew', | |
| 'Apple', | |
| 'Strawberry' | |
| ); | |
| foreach ($frults as $value) { |
This file contains hidden or 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 | |
| for ($i = 0; $i < 5; $i++): | |
| echo $i . PHP_EOL; | |
| endfor; | |
| /* | |
| Saída: |
This file contains hidden or 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 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; |