-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
GuhStvo
committed
Jul 2, 2024
1 parent
2c7197b
commit 64db56f
Showing
3 changed files
with
181 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
echo "<h2>Declarações de array's:</h2>"; | ||
echo "<br>"; | ||
|
||
$frutas = array("Maçã", "Banana", "Laranja", "Morango"); | ||
|
||
print_r($frutas); | ||
echo "<hr>"; | ||
|
||
$numeros = [2,2,6,9]; | ||
print_r($numeros); | ||
echo "<hr>"; | ||
|
||
$alunos = array("João" => 18, "Maria" => 20, "Pedro" => 19); | ||
print_r($alunos); | ||
echo "<hr>"; | ||
|
||
// acessando elementos | ||
echo "A segunda fruta é: $frutas[1] <br>"; | ||
echo "O terceiro número é: $numeros[2] <br>"; | ||
echo "A idade de João é :" . $alunos["João"]. "<br>"; | ||
|
||
// Alteração de elementos | ||
$frutas[0] = "Pera"; | ||
print_r($frutas); | ||
echo "<br>"; | ||
|
||
$numeros[4] = 100; | ||
print_r($numeros); | ||
echo "<br>"; | ||
|
||
$alunos["Maria"] = 21; | ||
$alunos["Ana"] = 21; | ||
print_r($alunos); | ||
echo "<br>"; | ||
|
||
/* push */ | ||
$frutas[] = "Abacaxi"; | ||
print_r($frutas); | ||
echo "<br>"; | ||
|
||
$numeros[] = 93; | ||
print_r($numeros); | ||
echo "<br>"; | ||
|
||
$alunos["José"] = 25; | ||
print_r($alunos); | ||
echo "<hr>"; | ||
|
||
// Percorrendo pelos elementos | ||
echo "Lista de frutas: "; | ||
foreach($frutas as $fruta) { | ||
echo "<li>$fruta</li>"; | ||
} | ||
echo "<br>"; | ||
|
||
echo "Lista de números: "; | ||
foreach($numeros as $numero) { | ||
// Escreva a lista de números. | ||
echo "<li>$numero</li>"; | ||
} | ||
echo "<br>"; | ||
|
||
echo "Lista de idades: "; | ||
foreach($alunos as $nome => $idade) { | ||
// Escreva a lista de números. | ||
echo "<li>$nome tem $idade anos.</li>"; | ||
} | ||
echo "<br>"; | ||
|
||
// Funções úteis para arrays | ||
|
||
/* Quantidade de dados em um array ".count($seuArrayAqui)" */ | ||
echo "Números de elementos no array de fruta é: " . count($frutas) . "<br>"; | ||
/* Indice de um array "arrat_search($seuArrayAqui)" */ | ||
echo "Índice de fruta 'Laranja': " . array_search("Laranja", $frutas) . "<br>"; | ||
|
||
/* Último dado de um array "end($seuArrayAqui)" */ | ||
echo "Última fruta do array: " . end($frutas) . "<br>"; | ||
|
||
print_r($frutas); | ||
echo "<br>"; | ||
/* Reverter array "array_reverse($seuArrayAqui)" */ | ||
echo "Array de frutas depois de reverter"; | ||
$frutas_revertida = array_reverse($frutas); | ||
print_r($frutas_revertida); | ||
?> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
/* EX 001 */ | ||
$diasSemana = array("Segunda-Feira", "Terça-Feira", "Quarta-Feira", "Quinta-Feira", "Sexta-Feira", "Sábado", "Domingo"); | ||
echo "<b>Dias da semana: </b>"; | ||
|
||
foreach($diasSemana as $diaSemana) { | ||
echo " $diaSemana | "; | ||
} | ||
echo "<br>"; | ||
echo "<b>Terceiro dia da semana: </b>" . $diasSemana[2]; | ||
|
||
echo "<hr>"; | ||
|
||
/* EX002 */ | ||
$mesesAno = array("Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"); | ||
echo "<br>"; | ||
foreach($mesesAno as $mes) { | ||
echo " $mes | "; | ||
} | ||
echo "<br>"; | ||
echo "<b>Último valor alterado: </b>"; | ||
echo "<br>"; | ||
$mesesAno[11] = "Onzembro"; | ||
|
||
foreach($mesesAno as $mes) { | ||
echo " $mes | "; | ||
} | ||
|
||
echo "<hr>"; | ||
|
||
|
||
/* EX003 */ | ||
|
||
$adicionarNum = array(1, 2, 3, 4, 5); | ||
echo "<b>Lista: </b>"; | ||
echo "<br>"; | ||
foreach($adicionarNum as $numeros) { | ||
echo " $numeros | "; | ||
} | ||
echo "<br>"; | ||
echo "<b>Adicionando valor: </b>"; | ||
echo "<br>"; | ||
$adicionarNum[] = 6; | ||
foreach($adicionarNum as $numeros) { | ||
echo " $numeros | "; | ||
} | ||
|
||
echo "<hr>"; | ||
|
||
|
||
/* EX004 */ | ||
echo "<b>Meses do ano: </b>"; | ||
echo "<br>"; | ||
$mesesAno[11] = "Dezembro"; | ||
|
||
foreach($mesesAno as $mes) { | ||
echo " $mes | "; | ||
} | ||
|
||
/* EX005 */ | ||
|
||
echo "<hr>"; | ||
|
||
echo "Existem " . "<b>" .count($diasSemana) . "</b>" . " Elementos no array de dias da semana."; | ||
|
||
echo "<hr>"; | ||
|
||
/* EX006 */ | ||
|
||
echo 'A posição do "Sábado" no array de dia da semana é: ' . array_search("Sábado", $diasSemana); | ||
?> |
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